for (int i = 0; i < list.Count; i++) { string chanId = list[i]["ChanId"]; string param = list[i]["param"]; ParameterizedThreadStart pts = null; if (chanId == "9") pts = new ParameterizedThreadStart(A); if (chanId == "521") pts = new ParameterizedThreadStart(B); if (chanId == "525") pts = new ParameterizedThreadStart(C); if (chanId == "526") pts = new ParameterizedThreadStart(D); if (chanId == "532") pts = new ParameterizedThreadStart(E); Thread th = new Thread(pts); th.Start(param); } 如果pts没赋值怎么办?代码我没测试,不过很可能是这个问题。也可能是每次都开线程,资源耗完了。
{
string chanId = list[i]["ChanId"];
string param = list[i]["param"];
ParameterizedThreadStart pts = null;
if (chanId == "9")
pts = new ParameterizedThreadStart(A);
if (chanId == "521")
pts = new ParameterizedThreadStart(B);
if (chanId == "525")
pts = new ParameterizedThreadStart(C);
if (chanId == "526")
pts = new ParameterizedThreadStart(D);
if (chanId == "532")
pts = new ParameterizedThreadStart(E);
Thread th = new Thread(pts);
th.Start(param);
}
如果pts没赋值怎么办?代码我没测试,不过很可能是这个问题。也可能是每次都开线程,资源耗完了。
我能告诉你的是,线程开多了程序不会直接崩溃退出,线程多了顶多是新开的线程不会运行,会处于等待状态,等有线程结束了,才会运行