今天天气不错,园子大丰收~~:

使用异步代理+IAsyncResult 调用函数

这是一个使用异步代理+IAsyncResult 调用函数的例子:

 

代码
namespace PTTool
{
class DownloadUpdate
{
public static string download(string Kbnumber)
{
FileOperation.CopyUpdates(Kbnumber);
return String.Format("{0} download complete...", Kbnumber);
}
}

public delegate string AsyncMethodCaller(string Kbnumber);
}

 

代码
namespace PTTool
{
partial class Program
{
static void Main(string[] args)
{
AsyncMethodCaller caller
= new AsyncMethodCaller(DownloadUpdate.download);

string num = Console.ReadLine();
IAsyncResult result
= caller.BeginInvoke(num, null, null);

while (!result.IsCompleted)
{
Thread.Sleep(
100);
Console.Write(
".");
}
Console.Write(caller.EndInvoke(result));
result.AsyncWaitHandle.Close();
}
}
}

 

 

Untitled

posted @ 2010-12-16 23:00  Jimson.Ma  阅读(258)  评论(0编辑  收藏  举报

Email: 20045912@163.com MSN: 20045912@163.com