Winform跨线程访问控件

public static void CrossThreadCalls(this Control ctl, ThreadStart del)
       {
           if (del == null) return;
           if (ctl.InvokeRequired)
               ctl.BeginInvoke(del, null);
           else
               del();
       }
扩展方法
var th = new Thread(() =>
            {
                label1.CrossThreadCalls(() => { label1.Enabled = !label1.Enabled; });
                WriteMessage(DateTime.Now.ToString());
            });
            th.IsBackground = true;
            th.Start();
调用示例

引用自:http://blog.csdn.net/dyllove98/article/details/9336451

posted @ 2013-11-01 15:09  无色无味  阅读(128)  评论(0)    收藏  举报