多线程
未将对象引用设置到对象的实例我用多个线程调用带参数的函数
初始化:
if (recvThread1==null)
{
recvThread1 = new Thread(new ParameterizedThreadStart(ReceiveData));
handleThread1=new Thread(new ParameterizedThreadStart(HandleRecvData));
}
else if (recvThread2 == null)
{
recvThread2 = new Thread(new ParameterizedThreadStart(ReceiveData));
handleThread2 = new Thread(new ParameterizedThreadStart(HandleRecvData));
}
后边调用:
recvThread1.Start(port1);
recvThread2.Start(port2);
运行后这条报错:recvThread2.Start(port2);———>未将对象引用设置到对象的实例
为什么啊...
------解决方案-------------------- else if (recvThread2 == null)
=>
if (recvThread2 == null)