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

使用异步代理+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 @   Jimson.Ma  阅读(259)  评论(0编辑  收藏  举报
努力加载评论中...

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

点击右上角即可分享
微信分享提示