|
4#
楼主 |
发表于 2014-2-23 10:26:57
|
只看该作者
[4]回调法,并且能够处理返回值","+多参数版"
- using System;
- using System.Threading;
- using System.Runtime.Remoting.Messaging;
- namespace PCTools
- {
- //delegate
- class Test
- {
- delegate string MyMethodDelegate(string s ,string t);
- static void Main(string[] args)
- {
- Console.WriteLine("========Test Begin=========");
- //Create
- B b = new B();
- //Start
- MyMethodDelegate MyMethod = b.Func;
- MyMethod.BeginInvoke("[5]回调法,并且能够处理返回值","+多参数版", CallBack, null);
- //方法五
- Thread fThread = new Thread(b.Func);
- fThread.Start("[4]处理单个参数");
- Console.WriteLine("===========Test End=========");
- Console.ReadKey();
- }
- static public void CallBack(IAsyncResult result)
- {
- AsyncResult async = (AsyncResult)result;
- MyMethodDelegate DelegateInstance = (MyMethodDelegate)async.AsyncDelegate;
- Console.WriteLine(DelegateInstance.EndInvoke(result));
- }
- }
- class B
- {
- public string Func(string s, string t)
- {
- return s + t;
- }
- public void Func(string s)
- {
- Console.WriteLine(s);
- }
- public void Func(object s)
- {
- this.Func((string)s);
- }
- }
- }
|
|