Example code details for the C # asynchronous Invoke proxy class

Source: Internet
Author: User
Calling the proxy class asynchronously
AsyncInvokeProxy.cs

Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading;namespace asyncinvokedemo{public    class asyncinvokeproxy<t1>    {        private action<t1> _task;        Public Asyncinvokeproxy (action<t1> Task)        {            this._task = task;        }        public void beginenvoke<t2> (T1 args, action<t2, exception> CB, T2 Cbargs)        {            this._task. BeginInvoke (args, new AsyncCallback (r) = =            {                Try                {                    cb (Cbargs, NULL);                    This._task. EndInvoke (R);                }                catch (Exception ex)                {                    CB (Cbargs, ex);                }}            ), Cbargs);    }}

Use:

using system;using system.collections.generic;using System.Linq;using System.text;namespace asyncinvokedemo{class Program {static void Main (string[] args) {Ac                tion<a> test = (A) + = {Console.WriteLine ("Start to invoke");                for (int i = 0; i < i++) {Console.WriteLine (i);            } Console.WriteLine ("Invoke args aint: {0},astr: {1}", A.aint, A.ASTR);            };            Asyncinvokeproxy<a> proxy = new asyncinvokeproxy<a> (test); Proxy.                Beginenvoke<b> (new A {aInt = 1, aStr = "AStr"}, (B, ex) + = {if (ex! = null)            {} Console.WriteLine ("Callback Ret bint: {0},bstr: {1}", B.bint, B.BSTR);            }, new B {bInt = 2, BSTR = "BSTR"});        Console.ReadLine (); }    }}

These are the contents of the sample code details for the C # asynchronous invocation proxy class, and more about topic.alibabacloud.com (www.php.cn)!

  • 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.