当我尝试这个时,我收到一条错误消息:
Task.Factory
.StartNew(() => _model.GetItems(node).Select(n => n))
.ContinueWith(t =>
{
if (t.Result != null)
{
ObservableCollection<ItemValue> children = new ObservableCollection<ItemValue>(t.Result);
//fill some control
}
}, TaskScheduler.FromCurrentSynchronizationContext());
错误
必须在与依赖对象相同的线程上创建依赖源
但如果我尝试这段代码:
Task.Factory
.StartNew(() => _model.GetItems(node).Select(n => n))
.ContinueWith(t =>
{
if (t.Result != null)
{
ObservableCollection<ItemValue> children = _model.GetItems(node);
//fill some control
}
}, TaskScheduler.FromCurrentSynchronizationContext());
没问题,没有错误。
我究竟做错了什么?
我想在另一个线程中填写集合。