考虑以下代码:
// MyKickAssTaskScheduler is a TaskScheduler, IDisposable
using (var scheduler = new MyKickAssTaskScheduler())
{
Task foo = new Task(() => DoSomething());
foo.ContinueWith((_) => DoSomethingElse());
foo.Start(scheduler);
foo.Wait();
}
ContinueWith()
任务是否保证在我的调度程序上运行?如果不是,它将使用哪个调度程序?
最佳答案
StartNew、ContinueWith 将默认为 TaskScheduler.Current、Current 将返回默认调度程序,当未从任务 (MSDN) 中调用时。
为避免默认调度程序问题,您应该始终将显式 TaskScheduler 传递给 Task.ContinueWith 和 Task.Factory.StartNew。
关于c# - 在哪个调度程序 Task.ContinueWith() 上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31111951/