码迷,mamicode.com
首页 > Windows程序 > 详细

winform Invoke, WPF Invoke

时间:2015-11-19 16:35:01      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

界面假死的代码:

void btnSecondEventMode_Click(object sender, EventArgs e)
 {
         btnSecondEventMode.BackColor = Color.Coral;
         Thread.Sleep(5000);
         MessageBox.Show("hello world");
 }

WinForm 异步调用

void BtnSecondEventAsyncModel_Click(object sender, EventArgs e)
{
        Action action = () =>
        {
            Task.Run(() =>
            {
                    BtnSecondEventAsyncModel.BackColor = Color.Coral;
                        Thread.Sleep(5000);
                    MessageBox.Show("hello world");
            });
 
        };
        BeginInvoke(action);
}                

WPF 异步调用

void BtnSecondEventAsyncModel_Click(object sender, EventArgs e)
{
        Action action = () =>
        {
            Task.Run(() =>
            {
                    BtnSecondEventAsyncModel.BackColor = Color.Coral;
                        Thread.Sleep(5000);
                    MessageBox.Show("hello world");
            });
 
        };
        Dispatcher.BeginInvoke(action);
}    

  

  

 

winform Invoke, WPF Invoke

标签:

原文地址:http://www.cnblogs.com/aquarius20th/p/4977718.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!