gpt4 book ai didi

.net - 连续的 .NET 并行 For - 每个之后阻塞

转载 作者:行者123 更新时间:2023-12-02 15:44:09 27 4
gpt4 key购买 nike

我连续进行了多个 Parallel.For 操作。

我目前正在检查每个 Parallel.For 的返回值 ParallelLoopResult 并休眠 20 毫秒,直到 IsCompleted 成员设置为 true。


Dim plr as ParallelLoopResult

plr = Parallel.For(...)

while not plr.IsCompleted
Thread.Sleep(20)
end while

plr = Parallel.For(...)

while not plr.IsCompleted
Thread.Sleep(20)
end while

.
.
.

如何添加内核级 block (即 WaitHandle)来代替循环和 Thread.Sleep? Parallel.For 是否触发完成事件? Parallel.For 是否提供了这样的机制?

最佳答案

Parallel.For 将完成调用它的所有代码。 IsCompleted 仅返回 false,然后循环被中断。

来自http://msdn.microsoft.com/en-us/library/system.threading.tasks.parallelloopresult.aspx :

If IsCompleted returns true, then the loop ran to completion, such that all iterations of the loop were executed. If IsCompleted returns false and LowestBreakIteration returns null, a call to Stop was used to end the loop prematurely. If IsCompleted returns false and LowestBreakIteration returns a non-null integral value, Break was used to end the loop prematurely.

关于.net - 连续的 .NET 并行 For - 每个之后阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4069738/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com