int count;
for(ing i=0;i<count;i++)
{
string ip ;
string port;
Thread newthread = new Thread(new ThreadStart(proc1));
newthread.name = "thread"+i.toString();
newthread.start()
}private void proc(string ip,string port)
{
}
每个线程的实际参数值都不同
(就是说i=0时可能ip=192.168.0.13,port = 80; i=1时ip=192.168.0.20,port=90.都是在循环内部计算得到的)该如何完成参数的传递。P。S 是1。1,没有ParameterizedThreadStart这东西可以用。在线等
for(ing i=0;i<count;i++)
{
string ip ;
string port;
Thread newthread = new Thread(new ThreadStart(proc1));
newthread.name = "thread"+i.toString();
newthread.start()
}private void proc(string ip,string port)
{
}
每个线程的实际参数值都不同
(就是说i=0时可能ip=192.168.0.13,port = 80; i=1时ip=192.168.0.20,port=90.都是在循环内部计算得到的)该如何完成参数的传递。P。S 是1。1,没有ParameterizedThreadStart这东西可以用。在线等
ThreadClass.IP = "192.168.0.13";
ThreadClass.Port = 8080;
Thread t = new Thread (new ThreadStart (ThreadClass.Fun );
t.Start ();
private class ThreadClass
{
public string IP;
public int Port; public void Fun()
{
//TO do Here
}
}
也可以直接将ip、port变量提升为字段。然后在
private void proc()
{
//todo.。。
}
如下代码:
int count;
string ip ;
string port;for(ing i=0;i<count;i++)
{
Thread newthread = new Thread(new ThreadStart(proc1));
newthread.name = "thread"+i.toString();
newthread.start()
}private void proc()
{
//todo ip port...
}