关于异步中的Completed

来源:百度知道 编辑:UC知道 时间:2024/05/27 06:01:12
现在微软的异步执行中大多使用了
...Completed+=new Delegate(...)
这种形式,谁有这种形式的实现代码!!!
是不是重新封装了BeginInvok和EndInvok方法?
已经自行解决
class TestClass{
public delegate void TestDelegate();
public event TestDelegate TestCompleted;
delegate void RunDelegate();
public TestClass()
{
AsyncCallBack ar=new AsyncCallBack (AsyncCallBack);
RunDelegate rd=new RunDelegate(RunMothod);
rd.BeginInvok(ar,rd);
}
void RunMothod()
{

}
void AsyncCallBack(IAsyncResult ia)
{
RunDelegate rd=ia.AsyncState as RunDelegate;
rd.EndInvok(ia);
if(TestCompleted!=null)
{
TestCompleted();
}
}
}
static void Main()
{
TestClass tc=new TestClass();
tc.TestCompleted+=new TestDelegate(方法名);
}

要申明一个委托
public void delegate CompletedHandler(参数1,参数2,。。。);
然后写一个方法
private void Completed(参数1,参数2,。。。)
{
....
}
调用
this.Invoke(new CompletedHandler(Completed), new object[] { 参数1,参数2,。。。});

多用于异步或不同线程间的操作

Completed+=new Delegate(...)
没见过这样的,你搞错了吧。