C#多线程传参


方法1:

public void Execute(string device,string type)

{
     object [] paras = new  object [] { device,type };
     new  Thread( new  ParameterizedThreadStart(tExecute)).Start(paras);
}
 
private  void  tExecute( object  para)
{
     object [] paras = ( object [])para;
     string  device = ( string )paras[0];
     string  type=( string )paras[1];
     。。。
}
方法2:

public void Execute(intx,inty)

{
   My m = new  My(); 
   m.x = x; 
   m.y = y; 
   Thread t = new  Thread( new  ThreadStart(m.C)); 
   t.Start(); 
}
  class  My 
  
     public  int  x, y; 
 
     public  void  C() 
    
       Console.WriteLine( "x={0},y={1}" , this .x, this .y); 
    
  
 
方法3:
  Thread t = new  Thread( new  ParameterizedThreadStart(Execute)); 
   t.Start( "B" ); 
  private  static  void Execute ( object  obj) 
  
   Console.WriteLine( "Execute{0}!" ,obj.ToString ()); 
 
  
 
 
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM