C# 如何仅阻止当前任务,而不阻止同一线程上的其他任务?
在C#中,是否有一种方法可以等待特定任务返回或在指定的毫秒数后超时,而不阻止在同一线程上运行的所有其他任务?假设您单独启动这些任务,而不使用Parallel.For/ForEach/Invoke等,也就是说,您正在取回一个任务对象,然后像这样:C# 如何仅阻止当前任务,而不阻止同一线程上的其他任务?,c#,multithreading,synchronization,C#,Multithreading,Synchronization,在C#中,是否有一种方法可以等待特定任务返回或在指定的毫秒数后超时,而不阻止在同一线程上运行的所有其他任务?假设您单独启动这些任务,而不使用Parallel.For/ForEach/Invoke等,也就是说,您正在取回一个任务对象,然后像这样: Task taskIWantToWaitFor = Task.Factory.Start(....); // Other code taskIWantToWaitFor.Wait(millisecondsTimeout) // All other tas
Task taskIWantToWaitFor = Task.Factory.Start(....);
// Other code
taskIWantToWaitFor.Wait(millisecondsTimeout)
// All other tasks continue in the background
假设您单独启动任务,而不是使用Parallel.For/ForEach/Invoke等,即您要返回一个任务对象,则类似如下:
Task taskIWantToWaitFor = Task.Factory.Start(....);
// Other code
taskIWantToWaitFor.Wait(millisecondsTimeout)
// All other tasks continue in the background
你能提供你想要解决的代码吗?你能提供你想要解决的代码吗?