先上代码
Program.cs
for(int i=0;i<XXX;i++){
    ClientThread newclient = new ClientThread("ID" + i);
    Thread newthread = new Thread(new ThreadStart(newclient.ClientService));
    newthread.Start();
}class ClientThread
{
    public String ID;
    private Queue<String> msgs;
    public ClientThread(String ID)
    {
        this.ID = ID;
        this.msgs = new Queue<String>();
    }
    public void ClientService()
    {
        // 访问别的指定线程中的msgs属性,并修改
        
    }
}
就是上面注释的地方,求高手赐教阿!!!!

解决方案 »

  1.   

    是这个意思吗?List<ClientThread> clients=new List<ClientThread> ();
    for(int i=0;i<XXX;i++){
      ClientThread newclient = new ClientThread("ID" + i);
      clients.Add (newclient );
      Thread newthread = new Thread(new ParameterizedThreadStart(newclient.ClientService));
      newthread.Start(clients);
    }class ClientThread
    {
      public String ID;
      private Queue<String> msgs;
      public ClientThread(String ID)
      {
      this.ID = ID;
      this.msgs = new Queue<String>();
      }
      public void ClientService(object context)
      {
           // 访问别的指定线程中的msgs属性,并修改
          IEnumerable  enumerable = context as IEnumerable ;
          if(enumerable==null)
          {
            return ;
          }
          foreach (ClientThread t in enumerable )
          {
            Console.WriteLine ("ID = {0}",t.ID);
              foreach (string s in t.msgs )
              {
                Console.WriteLine ("MSG = {0}",s);
              }
          } 
      }
      

  2.   

    to LyricSean
    不错不错!!!就是俺要的!!!多谢多谢,结帖了~~~