天天看點

C# 比較簡單的winform跨線程操作界面控件的方法

winform跨線程操作界面控件,一般用delegate比較多,不過寫法都好麻煩。網上找到一個比較快捷的寫法:

tbxTemp1.Invoke((MethodInvoker)delegate {
        tbxTemp1.Text = "XXX";
});
           

沒有大段的聲明或定義,很簡潔。不過它是同步的的,後面的代碼要等這塊執行完再繼續。

出處:https://stackoverflow.com/questions/661561/how-do-i-update-the-gui-from-another-thread

C# 比較簡單的winform跨線程操作界面控件的方法

還是美國網友厲害,各種原創内容。