我正在寻找一种方法来在另一个方法完成后立即启动一个方法。所以这就是想法:
第一个 Parallel.Invoke
将开始,例如 GetGroups()
完成后我想开始 InsertGroup()
和在 Insert_EventGroups()
之后。
Parallel.Invoke(() => { GetGroup(); },
() => { GetProfile(); });
Parallel.Invoke(() => { InsertGroup(); },
() => { InsertProfile(); });
Parallel.Invoke(() => { Insert_EventGroups(); },
() => { Insert_GroupProfiles(); });
我该怎么做?
最佳答案
只需按顺序调用它们,如果你想为组和配置文件使用多线程,你可以执行类似下面的操作(将方法重命名为更合适的名称):
Parallel.Invoke(() => { GroupStuff(); },
() => { ProfileStuff(); });
void GroupStuff()
{
GetGroup();
InserGroup();
Insert_EventGroups();
}
void ProfileStuff()
{
GetProfile();
InserProfile();
Insert_GroupProfiles();
}
关于c# - 当另一个完成使用多线程时启动一个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41571616/