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";

两者之间的区别:

Control.BeginInvoke:仍然是在UI线程,也就是说,界面仍然会卡住,但是这个函数将会执行结束,也就是说,str = "1";会被执行的。这就是和Control.Invoke 的区别。

Delegate.BeginInvoke:这个就是从ThreadTool 重新创建一个线程了,没什么好说了。

原文地址:https://www.cnblogs.com/sofire/p/1700719.html