gpt4 book ai didi

c# - 在 Parallel.foreach 中等待

转载 作者:太空狗 更新时间:2023-10-29 17:50:49 25 4
gpt4 key购买 nike

<分区>

我有一个将在 Parallel.Foreach 中使用的异步方法。在异步方法中有等待任务。但是,在测试中,似乎没有等待行为,等待任务没有完成。有什么问题?下面是代码。

public void method1()
{
Ilist<string> testList = new IList<string>(){"1","2","3"};
Parallel.ForEach(testList, ()=>
{
method2();
});
}
public async void method2()
{
await Task.run(()=>{ some other codes here });
}

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