在C#中是否有一种方法可以等到特定任务在指定的毫秒数后返回或超时,同时也阻止在同一个线程上运行的所有其他任务?
答案 0 :(得分:1)
假设您正在单独启动任务,而不是使用Parallel.For / ForEach / Invoke等,即您正在获取Task对象,那么类似这样的事情:
Task taskIWantToWaitFor = Task.Factory.Start(....);
// Other code
taskIWantToWaitFor.Wait(millisecondsTimeout)
// All other tasks continue in the background