[英]Why my Task.ContinueWith not wait the define time
I am using this method to open specific work with concurrent Threads from my Main UI thread: 我正在使用此方法从主UI线程中打开并发线程的特定工作:
private List<MyData> MyCollection;
private static CancellationTokenSource _tokenSource;
private void Start()
{
int concurrentThread = (int)nudConcurrentFiles.Value;
int loops = (int)nudLoops.Value;
var token = _tokenSource.Token;
Task.Factory.StartNew(() =>
{
try
{
while (Iteration.LoopFinished < loops)
{
Parallel.ForEach(PcapList.Files,
new ParallelOptions
{
MaxDegreeOfParallelism = concurrentThread //limit number of parallel threads
},
File=>
{
if (token.IsCancellationRequested)
return;
//do work...
});
Iteration.LoopFinished++;
Task.Delay(10000).ContinueWith(
t =>
{
}, _tokenSource.Token);
}
}
catch (Exception e)
{ }
}, _tokenSource.Token,
TaskCreationOptions.None,
TaskScheduler.Default).ContinueWith(
t =>
{
}
);
}
The problem is that after loop i want to wait 10 secons and Task.Delay(10000).ContinueWith
not waiting this 10 seconds but start immedietly another loop. 问题是循环后,我想等待10个secons和
Task.Delay(10000).ContinueWith
不等待这10秒钟,而是立即开始另一个循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.