具体看你连接到网络上作什么事情,比如说你是连接到某个网站上抓取信息的,那么一开始记录下所有要抓取的URL地址,给每个线程分配索引,只有成功抓取的线程索引+1,断网会引发超时异常,线程的索引就不会增加,下个线程启动的时候接着索引继续。 for (int i = 0; i < checkList.Count; i++) { switch (checkList[i].LoginStatus) { case AccountLoginStatus.ConnectionError: case AccountLoginStatus.NoLogin: case AccountLoginStatus.NeedCode: if (!this.threadRealmDict.ContainsKey(checkList[i])) { this.threadRealmDict.Add(checkList[i], new List<Thread>()); } this.threadRealmDict[checkList[i]].Clear(); Thread thread = new Thread(threadStart); thread.Start(checkList[i]); threadList.Add(thread); Thread.Sleep(ConfigManager.AppConfig.Sleep); break; } }
{
switch (checkList[i].LoginStatus)
{
case AccountLoginStatus.ConnectionError:
case AccountLoginStatus.NoLogin:
case AccountLoginStatus.NeedCode:
if (!this.threadRealmDict.ContainsKey(checkList[i]))
{
this.threadRealmDict.Add(checkList[i], new List<Thread>());
}
this.threadRealmDict[checkList[i]].Clear();
Thread thread = new Thread(threadStart);
thread.Start(checkList[i]);
threadList.Add(thread);
Thread.Sleep(ConfigManager.AppConfig.Sleep);
break;
}
}