title: Is there way to remove Thread Sleep code?
body: <p>With below code snippet, I am trying to do "Subscription to Windows Event Log".</p>
  
  <pre><code>using System;
  using System.Diagnostics.Eventing.Reader;
  
  namespace ConsoleApp1
  {
  class Program
  {
      static void Main(string[] args)
      {
  
          EventLogWatcher watcher = null;
          try
          {
              EventLogQuery subscriptionQuery = new EventLogQuery("Application", PathType.LogName, "*[System/EventID=101]");
  
              watcher = new EventLogWatcher(subscriptionQuery);
  
              watcher.EventRecordWritten += new EventHandler&lt;EventRecordWrittenEventArgs&gt;(EventLogEventRead);
  
              // Activate the subscription
              watcher.Enabled = true;
  
              for (int i = 0; i &lt; 5; i++)
              {
                  // Wait for events to occur. 
                  System.Threading.Thread.Sleep(10000);
              }
          }
          catch (EventLogReadingException e)
          {
              Console.WriteLine(e.Message);
          }
          finally
          {
              // Stop listening to events
              watcher.Enabled = false;
  
              if (watcher != null)
              {
                  watcher.Dispose();
              }
          }
  
          Console.ReadKey();
  
      }
  
      private static void EventLogEventRead(object obj, EventRecordWrittenEventArgs arg)
      {
          // Make sure there was no error reading the event.
          if (arg.EventRecord != null)
          {
              Console.WriteLine(arg.EventRecord.TimeCreated);
              Console.WriteLine(arg.EventRecord.FormatDescription());
          }
          else
          {
              Console.WriteLine("The event instance was null.");
          }
      }
  }
  }
  </code></pre>
  
  <p>Everything looks good over here, but is there any way that we can remove below thread sleep code?</p>
  
  <pre><code>for (int i = 0; i &lt; 5; i++)
              {
                  // Wait for events to occur. 
                  System.Threading.Thread.Sleep(10000);
              }
  </code></pre>
  
  <p>What could be other solution to that can invoke event happening?</p>