国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

借助封裝類實現線程調用帶參方法

2024-07-21 02:30:17
字體:
來源:轉載
供稿:網友

(一).描述
      由于線程只能執行無參數方法. 有時候需要線程執行"帶參數方法"
      此示例演示怎樣借助封裝類實現“線程調用帶參方法”
(二).代碼

本示例代碼已經測試,能夠正常運行!

(三).示例下載
  http://www.cnblogs.com/files/chengking/threadexample.rar

using system;
using system.threading;

namespace 借助封裝類實現_線程調用帶參方法_
{
 class help
 {
  public int x = 0;  //乘數1
  public int y = 0;  //乘數2
  public int end = 0; //存放結果
 }
 class myclass
 { 
  public static help  myhelp = new help();
       
         
  [stathread]
  static void main(string[] args)
  {
            //給類的成員賦值
   myhelp.x = 5;
   myhelp.y = 10;                
  
   thread thread = new thread(new threadstart(getaccumulate));
            thread.start();

   thread.sleep(1000); //主線程等待子線程計算完成,否則取得的值為默認值 : 0
  
   console.writeline("兩數乘積結果為: "+myhelp.end.tostring());

   console.read();
  
  }

  ///
  /// 得到兩個整數的集
  ///
  /// 乘數x
  /// 乘數y
  /// x*y
  public static void getaccumulate()
  {
   myhelp.end = myhelp.x * myhelp.y;
  }
 }
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 措美县| 澄城县| 潼南县| 丰县| 象州县| 广宗县| 买车| 永和县| 镇原县| 高邑县| 普宁市| 隆化县| 富源县| 四子王旗| 濮阳县| 晋中市| 宝清县| 林州市| 金阳县| 江孜县| 江门市| 开平市| 达州市| 米易县| 辰溪县| 福安市| 宝山区| 昌平区| 三门县| 贡嘎县| 平湖市| 吴忠市| 垫江县| 唐海县| 靖江市| 盖州市| 彩票| 大冶市| 兴隆县| 壤塘县| 大化|