可能重复:
如何创建运行 STA 线程的任务 (TPL)?
我正在使用以下代码:
var task = Task.Factory.StartNew<List<NewTwitterStatus>>(
() => GetTweets(securityKeys),
TaskCreationOptions.LongRunning);
Dispatcher.BeginInvoke(DispatcherPriority.Background,
new Action(() =>
{
var result = task.Result; // ERROR!!! The calling thread cannot access this object because a different thread owns it.
RecentTweetList.ItemsSource = result;
Visibility = result.Any() ? Visibility.Visible : Visibility.Hidden;
}));
我得到了错误:
var result = task.Result; // ERROR!!! The calling thread cannot access this object because a different thread owns it.
我需要做什么来解决这个问题?