說明:支持跨線程訪問控件。
定義代碼:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Forms;using System.Threading;namespace PackageOperMgr.util{ /// <summary> /// 跨線程訪問控件的委托 /// </summary> public delegate void InvokeDelegate(); /// <summary> /// 跨線程訪問控件類 /// </summary> public class InvokeUtil { /// <summary> /// 跨線程訪問控件 /// </summary> /// <param name="ctrl">Form對(duì)象</param> /// <param name="de">委托</param> public static void Invoke(Control ctrl, InvokeDelegate de) { if (ctrl.IsHandleCreated) { ctrl.BeginInvoke(de); } } /// <summary> /// 在線程中執(zhí)行代碼 /// </summary> public static void ExecuteCode(Control ctrl, InvokeDelegate de) { new Thread(new ThreadStart(delegate() { InvokeUtil.Invoke(ctrl, de); })).Start(); } }}View Code如何使用:

InvokeUtil.ExecuteCode(this, new InvokeDelegate(delegate(){ //這里寫您要執(zhí)行的代碼 string s = "aa" + "bb"; //例子 NextBtn.Enabled = false; //例子}));View Code新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注