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这东西可以用。在线等

解决方案 »

  1.   

    1.1就封装个类来传参 例如ThreadClass ThreadClass = new ThreadClass();
    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 
        }
    }
      

  2.   

    全局变量,再加一个sleep使各线程变量不冲突
      

  3.   

    jiatong1981(末日之痕)  的对.
      

  4.   

    jiatong1981(末日之痕)  的对.
      

  5.   

    jiatong1981(末日之痕)  的对.
      

  6.   

    楼上的是个办法
    也可以直接将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...
    }
      

  7.   

    chsword(邹健----非邹建老师) ,补充一下,那个sleep()在这边好象没有多大的意义。你说了