110,531
社区成员
发帖
与我相关
我的任务
分享
namespace ConsoleApplication1
{
class Program
{
public delegate string TakesAwhileDel(int data,int ms);
static void Main(string[] args)
{
TakesAwhileDel dl = TakesAwhile;
dl.BeginInvoke(1, 6000, AsyncCallbackImpl, dl);
System.Threading.Thread.Sleep(1000);
Console.ReadLine();
}
public static void AsyncCallbackImpl(IAsyncResult ar)
{
TakesAwhileDel dl = ar.AsyncState as TakesAwhileDel;
string re = dl.EndInvoke(ar);
Console.WriteLine("结果{0}", re);
//TakesAwhileDel d2 = TakesAwhile;
dl.BeginInvoke(1, 6000, AsyncCallbackImpl, dl);
}
static string TakesAwhile(int data, int ms)
{
Console.WriteLine("开始调用");
System.Threading.Thread.Sleep(ms);
Console.WriteLine("完成调用");
string str = "测试成功";
return str;
}
}
}
namespace ConsoleApplication1
{
class Program
{
public delegate string TakesAwhileDel(int data,int ms);
ManuResetEvent _BlockEvent=new ManuResetEvent(false);
static void Main(string[] args)
{
TakesAwhileDel dl = TakesAwhile;
dl.BeginInvoke(1, 6000, AsyncCallbackImpl, dl);
_BlockEvent.WaitOne();
Console.ReadLine();
}
public static void AsyncCallbackImpl(IAsyncResult ar)
{
TakesAwhileDel dl = ar.AsyncState as TakesAwhileDel;
string re = dl.EndInvoke(ar);
Console.WriteLine("结果{0}", re);
_BlockEvent.Set();
}
static string TakesAwhile(int data, int ms)
{
Console.WriteLine("开始调用");
System.Threading.Thread.Sleep(ms);
Console.WriteLine("完成调用");
string str = "测试成功";
return str;
}
}
}