/// <summary> /// define an event delegate that is signed with a method /// </summary> public delegate void Asynceventhandler (); /// <summary> /// defining callback method delegates with methods and signatures /// </summary> /// <param name= "EX" > Exception information Object </ Param> public delegate void asynccallbackhandler (EXCEPTION&NBSP;EX); /// <summary> /// Asynchronous call engine classes /// </summary> public class AsyncCallEngine { /// <summary> /// Execute asynchronous method call /// </summary > &nbSp; /// <param name= "Asyncmethod" > Methods for asynchronous Execution </param> /// <param name= "Callbackmethod" > Methods of asynchronous execution of methods after execution of callbacks < /param> public static void process ( Asynceventhandler asyncmethod, asynccallbackhandler callbackmethod) { try { //instantiation of Delegates and initial assignment AsyncEventHandler acd = new Asynceventhandler (Asyncmethod); //Instantiate callback method and subscribe asynccallback acb = new asynccallback (AR) => { //from asynchronous State ar. AsyncState, gets the delegate object acd = (Asynceventhandler) ar. asyncstate; Exception _ex = null; try { //asynchronous completion, execution callback method &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;ACD. EndInvoke (AR); } catch (Exception ex) { _ex = ex; } //Call callback function if (Callbackmethod != null) { callbackmethod (_EX); } } ); //Asynchronous Start IAsyncResult IAR&NBSP;=&NBSP;ACD. BeGininvoke (ACB,&NBSP;ACD); } catch (Exception ex) { //Call callback function if (callbackmethod != null) { callbackmethod (ex); } } } /// <summary> /// executing asynchronous method calls /// </summary> /// <param name= "Asyncmethod" > Methods for asynchronous Execution </param> public static void process (Asynceventhandler asyncmethod) { Process (asyncmethod, null); } }
Common asynchronous delay methods