如何用 Thread 呼叫視窗的函數?
基礎篇
C# 簡介
開發環境
變數與運算
流程控制
陣列
函數
物件
例外處理
函式庫篇
檔案處理
資料結構
正規表達式
Thread
應用篇
視窗程式
媒體影音
網路程式
遊戲程式
手機程式
資料庫
雲端運算
特殊功能
委派
擴展方法
序列化
LinQ
WPF
網路資源
教學影片
投影片
教學文章
軟體下載
考題解答
101習題
在 WinForm 等視窗中,必須使用 invoke() 這個函數,才能讓執行緒呼叫視窗中的函數,否則就會卡住,請參考下列網址與範例。
http://msdn.microsoft.com/zh-tw/library/zyzhdc6b(VS.80).aspx
// The following code assumes a 'ListBox' and a 'Button' control are added
to a form,
// containing a delegate which encapsulates a method that adds items to the
listbox.
public class MyThreadClass
{
MyFormControl myFormControl1;
public MyThreadClass(MyFormControl myForm)
{
myFormControl1 = myForm;
}
public void Run()
{
// Execute the specified delegate on the thread that owns
// 'myFormControl1' control's underlying window handle.
myFormControl1.Invoke(myFormControl1.myDelegate);
}
}
Post preview:
本網頁的作者、授權與引用方式
- 作者
- 陳鍾誠,於金門大學資訊工程系,電子郵件:wt.ude.uqn|ccc#wt.ude.uqn|ccc,網站:http://ccckmit.wikidot.com。
- 授權
- 本文採用創作共用 (Creative Common) 3.0 版的 姓名標示─非商業性─相同方式分享 授權條款,歡迎轉載或修改使用,但若做為商業使用時必須取得授權,引用本文時請參考下列格式。
- 中文版 (APA格式)
- 陳鍾誠 (18 Aug 2010 05:04),(網頁標題) 如何用 Thread 呼叫視窗的函數?,(網站標題) 免費電子書:C# 程式設計,18 Aug 2010 05:04,取自 http://cs0.wikidot.com/windowthread ,網頁修改第 0 版。
- 英文版 (APA格式)
- Chung-Chen Chen (18 Aug 2010 05:04), Retrieved 18 Aug 2010 05:04 from http://cs0.wikidot.com/windowthread, Page Revision 0.
page revision: 0, last edited: 18 Aug 2010 05:04