ManualResetEvent set waitone

 static void ManualResetEventFalseReset()
 {
     var signal = new ManualResetEvent(false);
     int x = 10;
     PrintLine();
     new Thread(() =>
     {
         PrintLine();
         x++;
         Thread.Sleep(1000);
         PrintLine();
         signal.Set();
     }).Start();
     PrintLine();
     Thread.Sleep(1000);
     PrintLine();
     signal.WaitOne();  
     PrintLine();
     Console.WriteLine(x);
 }

 static void PrintLine([CallerLineNumber] int lineNum=0)
 {
     Console.WriteLine($"{DateTime.Now.ToString("O")},line:{lineNum}");
 }

static void Main(string[] args)
{
    ManualResetEventFalseReset();
    LogInfo();
}

  

 

 

posted @ 2024-03-09 20:55  FredGrit  阅读(4)  评论(0编辑  收藏  举报