跨线程访问UI控件,请赏鉴

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SVS.ThreadHelper
{
    public static class ThreadSafe
    {
        public static void InvokeExt(this T t, Action method, params object[] args)
            where T : Control
        {
            if (t.InvokeRequired)
            {
                t.Invoke(method, args);
            }
            else
            {
                method.Method.Invoke(t, args);
            }
        }

        public static void InvokeExt(this T t, Action method)
             where T : Control
        {
            if (t.InvokeRequired)
            {
                t.Invoke(method);
            }
            else
            {
                method.Method.Invoke(t, null);
            }
        }
    }
}

相关资源:诗词鉴赏大全软件-教育文档类资源-CSDN文库

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2013年10月3日
下一篇 2013年10月4日

相关推荐