title: Find out if I'm on the unity thread
body: <p>How can I check if the thread I'm on is the Unity thread?</p>
  
  <p>I tried capturing the threadId at constructor time, but somewhere along the lifetime of the program, the threadId moves.</p>
  
  <p>In my project, some secondary thread processes need access to a newly created object.<br>
  I use the producer-consumer pattern so they can be created on the Unity thread.
  An object factory queues a request and on <code>Update()</code> the objects I requested are instantiated on the correct thread. Between Queued and Instantiated the factory method waits for an ObjectCreated event with an AutoResetEvent.</p>
  
  <p>Now sometimes this factory will be called from the main thread and the AutoResetEvent will block its own thread.
  I also tried it the dirty way with </p>
  
  <pre><code>// First try on this thread
  try
  {
      return action();
  }
  catch (ArgumentException ex)
  {
      Debug.Log("Tried on same thread, but failed. "+ex.Message);
  }
  PushToQueueAndWait(action);
  </code></pre>
  
  <p>But when unity throws the exception, caught or not, the program halts.</p>
  
  <p>If I could check whether I'm on the correct thread, I could switch between queueing and just executing.</p>