C WinForm 往執行緒裡傳引數的方法總結

2021-07-30 06:25:47 字數 4449 閱讀 4470

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

usingsystem;

usingsystem.collections.generic;

usingsystem.text;

usingsystem.threading;

namespaceaaaaaa

privatestaticvoida()

}

}

結果顯示method a! 

二、帶乙個引數的  

由於parameterizedthreadstart要求引數型別必須為object,所以定義的方法b形參型別必須為object。 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

usingsystem;

usingsystem.collections.generic;

usingsystem.text;

usingsystem.threading;

namespaceaaaaaa

privatestaticvoidb(objectobj)

!",obj.tostring ());

}

}

}

結果顯示method b! 

三、帶多個引數的  

由於thread預設只提供了這兩種建構函式,如果需要傳遞多個引數,我們可以自己將引數作為類的屬性。定義類的物件時候例項化這個屬性,然後進行操作。 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

usingsystem;

usingsystem.collections.generic;

usingsystem.text;

usingsystem.threading;

namespaceaaaaaa

}

classmy

,y=",this.x,this.y);

}

}

}

結果顯示x=2,y=3 

四、利用結構體給引數傳值。  

定義公用的public struct,裡面可以定義自己需要的引數,然後在需要新增執行緒的時候,可以定義結構體的例項。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

//結構體

structrowcol

;

//定義方法

publicvoidoutput(object rc)

", _char);

console.write("\n");

}

}

四、利用類給引數傳值。  

類: public string rowid, id;

thread thread = new thread(() => start_day(basecreatetask));//new thread(new threadstart(start_day(basecreatetask.basecreatetask)));

//將新建的執行緒加入到自定義執行緒佇列中,以便在窗體結束時關閉所有的執行緒

chaosthreadlist.add(thread);

thread.isbackground = true;

thread.start();

return;

//獲取每天的任務

private void start_day(object base_createtask)

}catch

}private void threaddayfunction(object createtask)

else

}catch

}

shell往awk傳引數

本文 記錄無限 www.gluoo.cn 今天在搞指令碼,需求是這樣的,有乙個檔案格式大概是這樣的 180 analyzer 20 job 1 需要按第一列的數值讀取這個檔案,比如第一行大於等於20的顯示出來,剛開始用的指令碼是這樣的 demo.sh bin bash threadhold 1 aw...

C 往執行緒裡傳遞引數的方法小結

傳參方式有兩種 1 建立帶參構造方法類 傳參 2 利用thread.start 8 直接傳參,該方法會接收乙個物件,並將該物件傳遞給執行緒,因此 程中啟動的方法 必須接收object型別的單個引數。thread parameterizedthreadstart 初始化 thread 類的新例項,指定...

從Windows用scp往linux裡傳輸檔案

有時候會需要從windows往linux伺服器copy檔案,直接copy的話會比較麻煩,可以用scp進行傳輸。因為windows系統本身不支援ssh協議,所以,要想上面的命令成功執行,必須在windows客戶端安裝ssh for windows的客戶端軟體,使windows系統支援ssh協議才行。這...