0
我必須在循環中產生配置爲no的多個線程。的網站,然後每個線程都有多個子線程。完成所有線程後,我需要執行一些任務將數據保存到數據庫中。我如何知道是否所有任務都已完成。
我當前的代碼:在循環中產生多個線程,並知道什麼時候所有完成了某些任務
List<SocialDataConfig> configList = SetConfiguration();
foreach (SocialDataConfig config in configList)
{
new Thread(delegate()
{
FetchSocialData(config);
}).Start();
}
// save fetched data into database and log fetched information in database
private void FetchSocialData(SocialDataConfig config)
{
for (int i = 0; i < config.ThreadCount; i++)
{
Thread thread = new Thread(delegate()
{
FetchData(54764876, config);
});
thread.Start();
}
}
謝謝。這個解決方案爲我工作。 –