title: Crossplatform threading and GTK#, not working (properly)?
body: <p>I'm trying to make a crossplatform C# application using C#, mono/GTK# on Linux and .NET/GTK# on Windows, however the startup sequence seems to need to be slightly different under the two platforms:</p>
  
  <p>Under Linux:</p>
  
  <pre><code>public static void Main (string[] args)
  {
      Gdk.Threads.Init ();
      // etc...
  </code></pre>
  
  <p>Under Windows:</p>
  
  <pre><code>public static void Main (string[] args)
  {
      Glib.Thread.Init ();
      Gdk.Threads.Init ();
      // etc...
  </code></pre>
  
  <p>Both require it to be done that way: Windows complains about g_thread_init() not being called with the linux code, and linux complains about it already being called with the Windows code. Other than this, it all works wonderfully.</p>
  
  <p>My first attempt at a "solution" looked like:</p>
  
  <pre><code>public static void Main (string[] args)
  {
      try {
          Gdk.Threads.Init ();
      } catch (Exception) {
          GLib.Thread.Init ();
          Gdk.Threads.Init ();
      }
      // etc...
  </code></pre>
  
  <p>But even this messy solution doesn't work; the error is coming from GTK+, unmanaged code, so it can't be caught. Does anyone have any bright ideas about the cause of the problem, and how to fix it? Or, failing that, have bright ideas on how to detect which one should be called at runtime?</p>