Control.BeginInvoke 和 Delegate.BeginInvoke 备忘
代碼段1:
?
string str = "0";
??????????? MessageBox.Show(str, "[ 溫馨提示 ]");
??????????? this.BeginInvoke(new Action(() =>
??????????????? {
??????????????????? for (int i = 0; i < 5; i++)
??????????????????? {
??????????????????????? Thread.Sleep(1000);
??????????????????? }
??????????????????? MessageBox.Show(str, "[ 溫馨提示 ]");
??????????????? }));
??????????? str = "1";
?
?
兩者之間的區(qū)別:
Control.BeginInvoke:仍然是在UI線程,也就是說(shuō),界面仍然會(huì)卡住,但是這個(gè)函數(shù)將會(huì)執(zhí)行結(jié)束,也就是說(shuō),str = "1";會(huì)被執(zhí)行的。這就是和Control.Invoke 的區(qū)別。
Delegate.BeginInvoke:這個(gè)就是從ThreadTool 重新創(chuàng)建一個(gè)線程了,沒(méi)什么好說(shuō)了。
?
轉(zhuǎn)載于:https://www.cnblogs.com/sofire/archive/2010/03/30/1700719.html
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的Control.BeginInvoke 和 Delegate.BeginInvoke 备忘的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【转】NIO的定义和原理是什么?
- 下一篇: JNDI学习总结(1)——JNDI入门简