gpt4 book ai didi

c# - 任务结果事件完成

转载 作者:太空狗 更新时间:2023-10-29 18:13:32 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How to create a task (TPL) running a STA thread?

我正在使用以下代码:

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.

我需要做什么来解决这个问题?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com