ThreadPool基础之RegisterWaitForSingleObject

http://www.cnblogs.com/Kazaf/archive/2012/03/26/2417341.html具体看这位写的即可

RegisterWaitForSingleObject的最后一个参数bool  如果是false就是循环 如果是true则只进一次

如果要跳出该循环则

 

static AutoResetEvent wait = new AutoResetEvent(false);
static void Main(string[] args)
{

 


object state = new object();
var reg = ThreadPool.RegisterWaitForSingleObject(wait, new WaitOrTimerCallback(test11), state, 1000, false);
Console.ReadKey();
//按回车即可跳出循环
reg.Unregister(wait);
Console.ReadKey();

 

}
private static void test11(object state, bool timedOut)
{
Console.WriteLine("aaa");
}

  

 

posted @ 2017-11-07 14:24  余旺旺  阅读(326)  评论(0编辑  收藏  举报