Code execution in the thread and code execution in the thread
Definition code:
Using System; using System. collections. generic; using System. linq; using System. text; using System. windows. forms; using System. threading; namespace PackageOperMgr. util {// <summary> /// delegate to the Cross-thread access control /// </summary> public delegate void InvokeDelegate (); /// <summary> /// cross-thread access control class /// </summary> public class InvokeUtil {/// <summary> // cross-thread access control // /</summary> /// <param name = "ctrl"> Form object </param> /// <param name = "de"> DeleGate </param> public static void Invoke (Control ctrl, invokeDelegate de) {if (ctrl. isHandleCreated) {ctrl. beginInvoke (de) ;}/// <summary> // run the code in the thread /// </summary> public static void ExecuteCode (Control ctrl, InvokeDelegate de) {new Thread (new ThreadStart (delegate () {InvokeUtil. invoke (ctrl, de );})). start ();}}}View Code
How to use:
InvokeUtil. executeCode (this, new InvokeDelegate (delegate () {// here write the code you want to execute string s = "aa" + "bb"; // example NextBtn. enabled = false; // example }));View Code