title: Error: IsObjectMonoBehaviour can only be called from the main thread
body: <p>I'm trying to reference one script from another in Unity. One of these scripts (API.cs) is sending a Post request to a server, while the other (Main.cs) is attempting to run its Post() method.</p>
  
  <p>However, I am seeing the following error message in the Unity debugger:</p>
  
  <blockquote>
    <p>IsObjectMonoBehaviour can only be called from the main thread.</p>
    
    <p>Constructors and field initializers will be executed from the loading thread when loading a scene.</p>
    
    <p>Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.</p>
    
    <p>UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)</p>
    
    <p>API:Post(MonoBehaviour) (at Assets/Scripts/API.cs:7)</p>
    
    <p>Main:m__0() (at Assets/Scripts/Main.cs:13)</p>
    
    <p>System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()</p>
  </blockquote>
  
  <p>I think this error has something to do with calling the non-static method, PostRequest() from within the StartCoroutine() method. However, I cannot make an IEnumerator "public static".</p>
  
  <p>This is the first project I've ever worked on in both C# and Unity, and I'm kind of at a loss here...</p>
  
  <p>Would really appreciate your input!</p>
  
  <hr>
  
  <p><strong>Main.cs</strong></p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using System.Threading.Tasks;
  using UnityEngine;
  
  public class Main : MonoBehaviour {
  
      void Start() {
  
          Task one = Task.Run(() =&gt; {
  
              API api = new API();
              api.Post(this);
          });
  
          one.Wait(-1);
      }
  }
  </code></pre>
  
  <p><strong>API.cs</strong></p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class API {
  
      public void Post(MonoBehaviour instance) {
  
          instance.StartCoroutine(PostRequest());
      }
  
      IEnumerator PostRequest() {
  
          ...
      }
  }
  </code></pre>