重複の可能性:
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.
この問題を解決するにはどうすればよいですか?