本文整理汇总了C#中System.Threading.CancellationToken.WaitCancellationRequested方法的典型用法代码示例。如果您正苦于以下问题:C# CancellationToken.WaitCancellationRequested方法的具体用法?C# CancellationToken.WaitCancellationRequested怎么用?C# CancellationToken.WaitCancellationRequested使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.CancellationToken
的用法示例。
在下文中一共展示了CancellationToken.WaitCancellationRequested方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Interval
public static Task Interval(
TimeSpan pollInterval,
Action action,
CancellationToken token,
bool isRepeat)
{
return Task.Factory.StartNew(
async () =>
{
if (!isRepeat)
{
await Task.Delay(pollInterval.Milliseconds);
action();
}
else
{
for (; ; )
{
if (token.WaitCancellationRequested(pollInterval))
break;
action();
}
}
}, token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
示例2: Interval
public static Task Interval(TimeSpan pollInterval, Action action, CancellationToken token)
{
return Task.Factory.StartNew(() => {
for (; ; )
{
if (token.WaitCancellationRequested(pollInterval))
break;
action();
}
}, token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
示例3: OnInterval
public static Task OnInterval(TimeSpan pollInterval, Action action, CancellationToken token,
TaskCreationOptions taskCreationOptions, TaskScheduler taskScheduler)
{
return Task.Factory.StartNew(() =>
{
for (;;)
{
if (token.WaitCancellationRequested(pollInterval))
break;
action();
}
}, token, taskCreationOptions, taskScheduler);
}
示例4: Interval
public static Task Interval(TimeSpan pollInterval, Action action, CancellationToken token)
{
// We don't use Observable.Interval:
// If we block, the values start bunching up behind each other.
return Task.Factory.StartNew(
() =>
{
for (; ; )
{
if (token.WaitCancellationRequested(pollInterval))
break;
action();
}
}, token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
}