title: C# Message Loop
body: <p>I'm trying to integrate a 3rd party C++ DLL with a C# application.  The 3rd party documentation says: </p>
  
  <blockquote>
    <p>"The application must have a Windows Message loop in order to the use the API. It is through the message loop that the TCP messages are sent..."</p>
  </blockquote>
  
  <p>My entry into the C# application is through a plugin framework, so it significantly more complicated that your average WinForms app however,  I'm not sure I understand the mapping between MFC message loops and the loops issued by Threading.Dispatcher as recommended <a href="https://stackoverflow.com/questions/2243499/net-message-loop"><strike>here</strike></a> and <a href="https://stackoverflow.com/questions/7392598/c-sharp-waiting-for-winforms-message-loop"><strike>here</strike></a></p>
  
  <p>If C# obfuscates this completely, I suppose I could run a message loop in my CLI layer and poll for messages from the C# plugin.</p>
  
  <p>I'm not even positive this is the issue; however my CLI layer works in a simple WinForms test application, but does not seem to catch callbacks with in the plugin ecosystem.</p>
  
  <p>Thanks S.O Community!</p>
  
  <p>UPDATE:
  Hmm, after looking more closely into the two links included above.  I'm not actually confident they are germane. </p>
  
  <p>Adding </p>
  
  <pre><code>Application.Run();
  </code></pre>
  
  <p>to my thread running the CLI layer does indeed pump the callbacks.  But then it crashes, or throws an Access Violation (that my generic catch( Exception) never catches..).  Frustratingly, <a href="https://stackoverflow.com/questions/5133971/finding-the-cause-of-system-accessviolationexception">this is the same error I get</a> but the comments just acknowledge that this happens.</p>
  
  <p>I don't have access to the form to get a handle or an application context. Most of answers I've found are for COM interfaces which this is not(i did try adding the STAThread attribute anyway, but to no avail. </p>
  
  <p>Is there another call that will pump the Windows message loop once so I can put it in my own loop?</p>