Possible Duplicate:
How to create a task (TPL) running a STA thread?
I'm using the following code:
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;
}));
And I'm getting the error:
var result = task.Result; // ERROR!!! The calling thread cannot access this object because a different thread owns it.
What do I need to do to resolve this problem?