zoukankan      html  css  js  c++  java
  • C# WinForm 异步执行耗时操作并将过程显示在界面中

     private void button3_Click(object sender, EventArgs e)
            {
                RunAsync(() =>
                {
                    // Just loop.
                    int ctr = 0;
                    for (ctr = 0; ctr <= 10; ctr++)
                    {
                        Thread.Sleep(2000);
                        RunInMainthread(() =>
                        {
                            textBox1.Text = ctr.ToString();
                        });
                    }
                  
                });
               
                MessageBox.Show("");
            }  // 异步线程
            public static void RunAsync(Action action)
            {
                ((Action)(delegate()
                {
                    action.Invoke();
                })).BeginInvoke(null, null);
            }
            public void RunInMainthread(Action action)
            {
                this.BeginInvoke((Action)(delegate()
                {
                    action.Invoke();
                }));
            }

  • 相关阅读:
    学习方法与经验总结
    工具综合症?资料收集狂?
    SpringMVC 过滤器Filter使用解析
    Spring 管理Filter和Servlet
    pom.xml配置详解
    开发Java web应用程序的介绍
    java web构建学习(概念基础)
    题目1474:矩阵幂
    题目1473:二进制数
    Python strip()方法
  • 原文地址:https://www.cnblogs.com/computer-lzy/p/8793685.html
Copyright © 2011-2022 走看看