System.IAsyncResult 接口
System.IAsyncResult接口编写异步方法中常用的一个接口,我在WF的InvokeMethod , WorkflowInvoker 例子中也用到了这个接口.由于有些朋友对System.IAsyncResult接口不了解,我特别写了一个实现System.IAsyncResult 接口的例子
{
{
}
System.Threading.WaitHandle asyncWaitHandle = new
{
}
{
}
{
}
{
{ _myValue = value; }
{
{
}
} } } |
{
{ asyncCallback = new asyncResult = new }
{
((AutoResetEvent)temp.AsyncWaitHandle).Set(); }
{
t.Start();
}
{
{
asyncResult.myValue = asyncResult.myValue + i;
}
asyncCallback(this.asyncResult); }
} |
{
{
r.AsyncWaitHandle.WaitOne();
System.Console.WriteLine(r.myValue);
System.Console.WriteLine("完成");
System.Console.Read(); } } |