Common asynchronous delay methods

Source: Internet
Author: User

    /// <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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.