title: Invoke method in main thread from other thread
body: <p>I get error like this in unity3d console:</p>
  
  <blockquote>
    <p>INTERNAL_CALL_Internal_InstantiateSingle  can only be called from the main thread.
    Constructors and field initializers will be executed from the loading thread when loading a scene.
    Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.</p>
  </blockquote>
  
  <p>What I'm trying is execute method which seems to be defined in main thread like "Instantiate()"</p>
  
  <p>How can I invoke this method or call main thread to execute it?</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>protected static void processCommand(String data) {
      ...
      } else if(data.StartsWith("LOGGEDIN")) {
          ...
          Vector3 pos = new Vector3(0, 1.2F, 0);
          Quaternion rot = Quaternion.identity;
          myModel = (GameObject)Instantiate(player, pos, rot);
  ...
  </code></pre>
  
  <p>and the thread is:</p>
  
  <pre><code>Thread tidListen = new Thread(new ThreadStart(ListenThread));
  tidListen.Start();
  
  private static void ListenThread() {
          while(connected) {
              int lData = myStream.Read(myBuffer, 0, client.ReceiveBufferSize);
              String myString = Encoding.ASCII.GetString(myBuffer);
              myString = myString.Substring(0, lData);
              processCommand(myString);
          }
      }
  </code></pre>
  
  <p>when i call processCommand i have there the method: Instantiate()</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>I tried this also <a href="http://forums.asp.net/t/1777525.aspx/1" rel="nofollow">Link</a>, when i get the ManagedThreadId from currentThread i get 1 (which seems to be main thread) but i get again the same error.</p>