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