这是一个使用异步代理+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();
}
}
}