title: Task returns "call thread can't access this object"
body: <p>I want to create an array with all the plugins installed on streamlinks and then compare it with a given string, to check if the app has a supporting plugin for the given site. I don't want to freeze the app for that, so a while loop inside a sync method would not fit me, so I tried to do it with Tasks.</p>
  
  <p>This is the code of my app:</p>
  
  <pre class="lang-cs prettyprint-override"><code>private void SupportCheckButton_Click(object sender, RoutedEventArgs e)
  {
      Task&lt;bool&gt; task = Task.Run(async () =&gt; await Methods.isSiteSupported(LinkText.Text));
  
      task.Wait();
      if (task.Result)
      {
          cmdOutputLabel.AppendText(new Uri(Methods.FormatedUrl(LinkText.Text)).Host + " is supported.");
      }
      else
      {
          cmdOutputLabel.AppendText(new Uri(Methods.FormatedUrl(LinkText.Text)).Host + " is not supported. Yet...");
      }
  }
  </code></pre>
  
  <p>This is the code for my <code>library</code>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>private static void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
  {
      if(!string.IsNullOrWhiteSpace(e.Data))
          plugins = e.Data.Split(',');
  }
  
  public static async Task&lt;bool&gt; isSiteSupported(string site)
  {
      try
      {
          site = FormatedUrl(site);
          if (GetUrlResponse(site))
          {
              string siteDomain = new Uri(site).Host;
              string[] siteDivided = siteDomain.Split('.');
  
              if (siteDivided.Length == 2)
                  siteDomain = siteDivided[0];
              else if (siteDivided.Length &gt;= 2)
              {
                  siteDomain = string.Empty;
                  for (int i = 0; i &lt; siteDivided.Length - 1; i++)
                  {
                      siteDomain += siteDivided[i];
                  }
              }
  
              Process proc = new Process
              {
                  StartInfo = new ProcessStartInfo
                  {
                      FileName = "CMD.exe",
                      Arguments = "/C streamlink --plugins",
                      UseShellExecute = false,
                      RedirectStandardOutput = true,
                      CreateNoWindow = true
                  }
              };
              proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
              proc.Start();
              proc.BeginOutputReadLine();
              if (plugins == null)
              {
                  await GetPluginList();
              }
              return plugins.Contains(siteDomain);
          }
          else
          {
              return false;
          }
      }
      catch
      {
          return false;
      }
  }
  
  public static async Task&lt;string&gt; GetPluginList()
  {
      await Task.Run(() =&gt; {
          while (plugins == null)
          {
              System.Threading.Thread.Sleep(500);
          }
          if (plugins.Length &gt; 0)
          {
              if (plugins[0].Contains("Loaded plugins: "))
                  plugins[0] = plugins[0].Remove(plugins[0].IndexOf("Loaded plugins: "), 10);
              for (int i = 0; i &lt; plugins.Length; i++)
              {
                  plugins[i] = plugins[i].Trim();
              }
          }
      });
      return null;
  }
  </code></pre>
  
  <p>But after many tries I was not able to do it properly. Right now, with this exact code, it returns an <code>InvalidOperationException</code> saying that the Call Thread can't access <code>Task.Wait();</code> object, because it is being used in another Thread. Anyhow I can't see what other thread is using it.</p>