我有一个异步方法,将在Parallel.Foreach中使用。在异步方法中,有一个等待Task的await。
然而,在测试中,似乎没有等待行为,await Task没有完成。问题出在哪里?以下是代码。
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 });
}