title: .NET and ComVisible in non-WinForms app
body: <p>I have a .NET program that uses pinvoke to run a traditional Win32 message loop and display a UI.  This program also exposes COM interfaces for UI Automation accessibility.</p>
  
  <p>How do I know when all the references to these COM interfaces have been released so that I can safely terminate the message loop and shutdown the app?  </p>
  
  <p>Normally a out-of-proc COM server would maintain a global object reference count and server lock count.  Presumably this is done by the CLR somewhere and WinForms and WPF's Application.Run methods track this however I haven't been able to find any documentation for how to implement this myself.</p>