public void Dispose()
{
if (_cancellationToken != null && !_cancellationToken.IsCancellationRequested)
{
try
{
_cancellationToken.Cancel();
_resetEvent.Set();
}
catch (Exception ex)
{
_logger.Error("An error occured cancelling the web deploy lease thread.", ex);
}
}
if (_leaseId == null) return;
try
{
var blob = AzureRoleEnvironment.WebDeployLeaseBlob();
blob.TryReleaseLease(_leaseId);
blob.Metadata.Remove("InstanceId");
blob.SetMetadata();
_leaseId = null;
}
catch (Exception ex)
{
_logger.Error("An exception occured when attempting to clear the InstanceId from the web deploy lease metadata.", ex);
}
}