说明:支持跨线程访问控件。
定义代码:
using System; System.Collections.Generic; System.Linq; System.Text; System.Windows.Forms; System.Threading; namespace PackageOperMgr.util { /// <summary> /// 跨线程访问控件的委托 </summary> public delegate void InvokeDelegate(); 跨线程访问控件类 class InvokeUtil { <summary> 跨线程访问控件 </summary> <param name="ctrl">Form对象</param> <param name="de">委托</param> static Invoke(Control ctrl,InvokeDelegate de) { if (ctrl.IsHandleCreated) { ctrl.BeginInvoke(de); } } 在线程中执行代码 </summary> ExecuteCode(Control ctrl,1)">new Thread(new ThreadStart(delegate() { InvokeUtil.Invoke(ctrl,de); })).Start(); } } }
如何使用:
InvokeUtil.ExecuteCode(this,new InvokeDelegate(() { //这里写您要执行的代码 string s = "aa" + bb"; 例子 NextBtn.Enabled = false; 例子 }));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。