本文整理汇总了C#中System.Threading.CancellationToken.WhenCancelled方法的典型用法代码示例。如果您正苦于以下问题:C# CancellationToken.WhenCancelled方法的具体用法?C# CancellationToken.WhenCancelled怎么用?C# CancellationToken.WhenCancelled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.CancellationToken
的用法示例。
在下文中一共展示了CancellationToken.WhenCancelled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
/// <summary>
/// Runs the services and waits for termination.
/// </summary>
/// <param name="cancellationToken">
/// The cancellation token.
/// </param>
/// <returns>
/// A <see cref="Task"/> representing the work performed.
/// </returns>
private static async Task Run(CancellationToken cancellationToken)
{
try
{
var factory = new ServiceFactory();
Console.WriteLine("Initializing runtime.");
var timeout = TimeSpan.FromMinutes(1);
using (var fabric = await FabricRuntime.CreateAsync(timeout, cancellationToken))
{
Console.WriteLine("Registering services.");
await
fabric.RegisterStatelessServiceFactoryAsync(
Service.ServiceTypeName,
factory,
timeout,
cancellationToken);
ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(OrleansFabricSilo).Name);
Console.WriteLine("Services running.");
await Task.WhenAny(factory.Stopped, cancellationToken.WhenCancelled());
}
}
catch (Exception e)
{
ServiceEventSource.Current.ServiceHostInitializationFailed(e);
throw;
}
finally
{
Console.WriteLine("Terminating.");
}
}