本文整理匯總了C#中ActionableProgress.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# ActionableProgress.Dispose方法的具體用法?C# ActionableProgress.Dispose怎麽用?C# ActionableProgress.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ActionableProgress
的用法示例。
在下文中一共展示了ActionableProgress.Dispose方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: InstallPackage
//.........這裏部分代碼省略.........
if (progress == null)
{
throw new ArgumentNullException("progress");
}
if (cancellationToken == null)
{
throw new ArgumentNullException("cancellationToken");
}
var installationInfo = new InstallationInfo
{
Id = Guid.NewGuid(),
Name = package.name,
UpdateClass = package.classification,
Version = package.versionStr
};
var innerCancellationTokenSource = new CancellationTokenSource();
var tuple = new Tuple<InstallationInfo, CancellationTokenSource>(installationInfo, innerCancellationTokenSource);
// Add it to the in-progress list
lock (CurrentInstallations)
{
CurrentInstallations.Add(tuple);
}
var innerProgress = new ActionableProgress<double>();
// Whenever the progress updates, update the outer progress object and InstallationInfo
innerProgress.RegisterAction(percent =>
{
progress.Report(percent);
installationInfo.PercentComplete = percent;
});
var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationTokenSource.Token).Token;
var installationEventArgs = new InstallationEventArgs
{
InstallationInfo = installationInfo,
PackageVersionInfo = package
};
EventHelper.QueueEventIfNotNull(PackageInstalling, this, installationEventArgs, _logger);
try
{
await InstallPackageInternal(package, innerProgress, linkedToken).ConfigureAwait(false);
lock (CurrentInstallations)
{
CurrentInstallations.Remove(tuple);
}
CompletedInstallations.Add(installationInfo);
EventHelper.QueueEventIfNotNull(PackageInstallationCompleted, this, installationEventArgs, _logger);
}
catch (OperationCanceledException)
{
lock (CurrentInstallations)
{
CurrentInstallations.Remove(tuple);
}
_logger.Info("Package installation cancelled: {0} {1}", package.name, package.versionStr);
EventHelper.QueueEventIfNotNull(PackageInstallationCancelled, this, installationEventArgs, _logger);
throw;
}
catch (Exception ex)
{
_logger.ErrorException("Package installation failed", ex);
lock (CurrentInstallations)
{
CurrentInstallations.Remove(tuple);
}
EventHelper.QueueEventIfNotNull(PackageInstallationFailed, this, new InstallationFailedEventArgs
{
InstallationInfo = installationInfo,
Exception = ex
}, _logger);
throw;
}
finally
{
// Dispose the progress object and remove the installation from the in-progress list
innerProgress.Dispose();
tuple.Item2.Dispose();
}
}