title: C# SetWinEventHook stops sending messages on mouse move
body: <p>In my C# WPF application.</p>
  
  <p>I am setting a hook in the window Initialized callback:</p>
  
  <pre><code>[DllImport("user32.dll")]
  static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess,  uint idThread, uint dwFlags);
  
  IntPtr hookHandle = SetWinEventHook(EVENT_MIN, EVENT_MAX, IntPtr.Zero, TestCallback, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS | WINEVENT_SKIPOWNTHREAD);
  </code></pre>
  
  <p>and I am logging the message in the callback</p>
  
  <pre><code>private void TestCallback(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
  {
      SetStatus("The eventType is: " + eventType);
  }
  </code></pre>
  
  <p>However, whenever I mouse over the space in my WPF window.</p>
  
  <p>The events stop sending completely.</p>
  
  <p>On a possibly unrelated note, I was getting a </p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object</p>
  </blockquote>
  
  <p>Unhandled exception in one of the system dlls sometimes.</p>
  
  <p>Why does mousing over cause the win hook to fail?</p>
  
  <p>My ultimate goal is to get an event whenever a new window is created/shown on the desktop so that I don't have to poll it in a loop that takes a lot of CPU.</p>