Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何仅阻止当前任务,而不阻止同一线程上的其他任务?_C#_Multithreading_Synchronization - Fatal编程技术网

C# 如何仅阻止当前任务,而不阻止同一线程上的其他任务?

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

在C#中,是否有一种方法可以等待特定任务返回或在指定的毫秒数后超时,而不阻止在同一线程上运行的所有其他任务?

假设您单独启动这些任务,而不使用Parallel.For/ForEach/Invoke等,也就是说,您正在取回一个任务对象,然后像这样:

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

你能提供你想要解决的代码吗?你能提供你想要解决的代码吗?