异步回调是指异步执行一个带回调函数的方法;代码如下
class Program
{
static void Main(string[] args)
{
Action<string> A1 = new Action<string>(Show);
A1.BeginInvoke("Hello", Callback, "回调参数");
Console.Read();
}
//回调方法
public static void Callback(IAsyncResult ar)
{
object str = ar.AsyncState as string;
Console.WriteLine(str);
}
//委托方法
public static void Show(string str)
{
Console.WriteLine(str);
}
}
{
static void Main(string[] args)
{
Action<string> A1 = new Action<string>(Show);
A1.BeginInvoke("Hello", Callback, "回调参数");
Console.Read();
}
//回调方法
public static void Callback(IAsyncResult ar)
{
object str = ar.AsyncState as string;
Console.WriteLine(str);
}
//委托方法
public static void Show(string str)
{
Console.WriteLine(str);
}
}
输出结果是:Hello
回调参数