异步调用代理类
asyncinvokeproxy.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace AsyncInvokeDemo
{
public class AsyncInvokeProxy
{
private Action _task;
public AsyncInvokeProxy(Action task)
{
this._task = task;
}
public void BeginEnvoke(T1 args, Action 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);
}
}
} 使用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AsyncInvokeDemo
{
class Program
{
static void Main(string[] args)
{
Action test = (a) =>
{
Console.WriteLine("start to invoke");
for (int i = 0; i < 1000; i++)
{
Console.WriteLine(i);
}
Console.WriteLine("invoke args aint : {0},astr: {1} ", a.aInt, a.aStr);
};
AsyncInvokeProxy proxy = new AsyncInvokeProxy(test);
proxy.BeginEnvoke(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();
}
}
} 以上就是C# 异步调用代理类的示例代码详情的内容,更多相关内容请关注PHP中文网(www.php.cn)!
超级适合代理建设企业站点的企业源码,超方面实用!程序说明: 1.特色:简繁中文切换、产品展示系统、新闻发布系统、会员管理系统、留言本计数器、网站信息统计、强大后台操作 功能等; 2.页面包括:首页、企业介绍、滚动公告通知发布系统、企业新闻系统、产品展示系统、企业案例发布展示系 统、企业招聘信息发布系统、信息资源下载系统、在线定单系统、在线客服系统、在线留言本系统、网站调查投票系统、友情连接系统、会









