using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace threading
{
public delegate int TakesAWhileDelegate(int data,int ms);
class Program
{
static int TakesAWhile(int data, int ms)
{
Console.WriteLine("TakesAWhile started");
Thread.Sleep(ms);
Console.WriteLine("TakesAWhile completed");
return ++data;
}
static void Main(string[] args)
{
TakesAWhileDelegate d1 = TakesAWhile;
IAsyncResult ar = d1.BeginInvoke(1, 3000, null, null);
while (true)
{
Console.Write(".");
if (ar.AsyncWaitHandle.WaitOne(50, false))
{
Console.WriteLine("can get the result now");
break;
}
}
int result = d1.EndInvoke(ar);
Console.WriteLine("result:{0}", result);
Console.ReadKey();
}
}
}
if (ar.AsyncWaitHandle.WaitOne(50, false))中的false改写为true后效果为什么依然相同?
这个方法不起作用,
net内部的自动管理默认超时时间(一个socket缓存时间)不超过70秒