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)!