WinForm多執行緒 委託防止介面卡死

2023-03-19 04:30:34 字數 1189 閱讀 8845

1、當有大量資料需要計算、顯示在介面或者呼叫sleep函式時,容易導致介面卡死,可以採用多執行緒加委託的方法解決

using

system;

using

system.collections.generic;

using

system.componentmodel;

using

system.data;

using

system.drawing;

using

system.text;

using

system.windows.forms;

using

system.io;

using

system.diagnostics;

using

system.runtime.interopservices;

using

system.threading;

namespace

windowsformtest

thread drawthread = null

;

delegate

void drawdelegate(int

i);

//開啟子執行緒

private

void btntest_click(object

sender, eventargs e)

//draw子執行緒,迴圈呼叫test函式,並且等待一會

private

void

draw()

}catch

(system.exception e1)

closethread();

}//test函式,向textbox中新增資料

private

void test(int

i) );

} else

}

//結束子執行緒

private

void

closethread()}}

//窗體關閉時,關閉子執行緒

private

void form1_formclosing(object

sender, formclosingeventargs e)

}}

WinForm多執行緒及委託防止介面假死

當有大量資料需要計算 顯示在介面或者呼叫sleep函式時,容易導致介面卡死,可以採用多執行緒加委託的方法解決。using system using system.collections.generic using system.componentmodel using system.data usi...

2014 9 13 委託多執行緒

週六學習的時間。繼續學習委託,多執行緒。1.簡單委託的定義 delegate int mydel int a,int b mydel mydel new mydel add add方法必須和委託mydel有相同的引數和返回值 mydel add2 多播委託 2.匿名函式 mydel del dele...

winform總結6 執行緒和委託的關係

基礎類 using system using system.collections.generic using system.linq using system.text using system.threading.tasks namespace 執行緒和事件的關係 public delegate...

C 委託和多執行緒

很多時候寫windows程式都需要結合多執行緒,在.net中用如下得 來建立並啟動一個新的執行緒。public void threadproc thread thread new thread new threadstart threadproc thread.isbackground true t...

C 多執行緒 委託ThreadStart

using system using system.collections.generic using system.linq using system.text using system.threading.tasks using system.threading namespace create...

WPF 多執行緒與委託

public mainwindow delegate void mydelegate string msg mydelegate mydele thread t private void button1 click object sender,routedeventargs e t new thre...

非同步委託與多執行緒

private delegate void asynceventhandler asynceventhandler asy new asynceventhandler delegate iasyncresult ia asy.begininvoke new asynccallback callbac...

非同步委託與多執行緒

private delegate void asynceventhandler asynceventhandler asy new asynceventhandler delegate iasyncresult ia asy.begininvoke new asynccallback callbac...

委託的多執行緒方法BeginInvoke

同步方法呼叫在程式繼續執行之前需要等待同步方法執行完畢返回結果。比如燒水泡茶,需要等水燒開了才能繼續泡茶 非同步方法則在被呼叫之後立即返回以便程式在被呼叫方法完成其任務的同時執行其它操作。比如燒水做飯,當水燒著的時候,還可以做飯 private void download string filena...

執行緒5 委託開啟執行緒

使用委託開啟一個執行緒,引數傳遞,以及獲取執行緒的返回數值。例子 action ac threadmethod1 ac.begininvoke null,null 注意 委託開啟的執行緒都是後臺執行緒,後臺執行緒會隨著前臺執行緒的關閉而自動關閉 源 學習使用委託開啟執行緒 注意 委託開啟的執行緒都是...