为什么我的Task.ContinueWith没有等待定义时间

时间:2015-08-09 14:32:53

标签: c# task

我正在使用此方法从我的主UI线程中使用并发线程打开特定的工作:

img = document.getElementById('image'); // which is an <img> element

if (img.width > 0) {
    // I get here in Chrome, width is correct
} else {
    // I get here in Safari, width is 0
}

问题是在循环之后我想等待10个secons并且 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 => { } ); } 不等待这10秒但是立即开始另一个循环。

1 个答案:

答案 0 :(得分:0)

您需要调用Wait()方法才能执行任务

div.ColVis, button.ColVis_Button {
  float:none;
}