title: The calling thread must be STA, because many UI components require this
body: <p>I am using <a href="http://www.codeproject.com/KB/IP/Facebook_API.aspx" rel="noreferrer">http://www.codeproject.com/KB/IP/Facebook_API.aspx</a></p>
  
  <p>I am trying to call the <a href="http://en.wikipedia.org/wiki/Extensible_Application_Markup_Language" rel="noreferrer">XAML</a> which is created using <a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation" rel="noreferrer">WPF</a>. But it gives me an error:</p>
  
  <blockquote>
    <p>The calling thread must be STA, because many UI components require this.</p>
  </blockquote>
  
  <p>I don't know what to do. I am trying to do this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>FacebookApplication.FacebookFriendsList ffl = new FacebookFriendsList();
  </code></pre>
  
  <p>But it is giving me that error.</p>
  
  <p>I added a background worker:</p>
  
  <pre class="lang-cs prettyprint-override"><code>static BackgroundWorker bw = new BackgroundWorker();
  
  static void Main(string[] args)
  {
      bw.DoWork += bw_DoWork;
      bw.RunWorkerAsync("Message to worker");
      Console.ReadLine();
  }
  
  static void bw_DoWork(object sender, DoWorkEventArgs e)
  {
      // This is called on the worker thread
      FacebookApplication.FacebookFriendsList ffl = new FacebookFriendsList();
  
      Console.WriteLine(e.Argument);        // Writes "Message to worker"
  
      // Perform time-consuming task...
  }
  </code></pre>