调用线程必须是STA,因为很多UI组件都需要这个 [英] The calling thread must be STA, because many UI components require this
本文介绍了调用线程必须是STA,因为很多UI组件都需要这个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 http://www.codeproject.com/KB/IP/Facebook_API.aspx
我正在尝试调用使用 WPF.但它给了我一个错误:
I am trying to call the XAML which is created using WPF. But it gives me an error:
调用线程必须是 STA,因为很多 UI 组件都需要这个.
The calling thread must be STA, because many UI components require this.
我不知道该怎么办.我正在尝试这样做:
I don't know what to do. I am trying to do this:
FacebookApplication.FacebookFriendsList ffl = new FacebookFriendsList();
但它给了我那个错误.
我添加了一个后台工作人员:
I added a background worker:
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...
}
推荐答案
尝试从 调度员:
Application.Current.Dispatcher.Invoke((Action)delegate{
// your code
});
这篇关于调用线程必须是STA,因为很多UI组件都需要这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文