English 中文(简体)
• 如何处理可观测到的Collection<>,这是在MVVER公司的一个平行任务的结果?
原标题:How to handle ObservableCollection<> result from a parallelized Task in MVVM?

我正在单独收集一个任务中的数据,我希望数据将结果与使用<代码>的全球倡议组成部分联系起来。 ObservableCollection<>。 因此,我的准则类似:

private ObservableCollection<MyItem> _items;
public ObservableCollection<MyItem> Items
{
  get { return _items; }
  set
  {
    if (_items.Equals(value))
    {
      return;
    }
    _items = value;
    RaisePropertyChanged("Items");
  }
}

private void LoadData()
{
  Task task = Task.Factory.StartNew(() =>
  {
    ObservableCollection<MyItem> itms = _htmlParser.FetchData(...);

    Dispatcher.CurrentDispatcher.Invoke((Action)delegate
    {
      Items = itms;
    });
  });
}

The data is fetched from a component doing some HTTP requests. The error I am getting is:
Must create DependencySource on same Thread as the DependencyObject.

我正在使用MTV光工具包框架。 我也试图将结果作为信息发出,但结果却以同样的错误信息告终。 任何想法或要点?

EDIT:本问题:

public class MyItem
{
  public string Id { get; set; }
  public string Name { get; set; }
  public BitmapImage Image { get; set; }  // <--- A big No No because it inherits from the DependencyObject
  public Uri Uri { get; set; }
}

我将<代码>BitmapImage改为byte[]数据类型。

最佳回答

您重新获得的例外情况(“Must Creat DependencySource on same Thread as the DependencyObject”)表明,一些东西是在一种背景的read子上制造的,并用于ID的read。 是否正在建立并储存在收集中,供国际钻石联合会使用?

我看到,可以观察的Collection公司本身是在背景的read子下建立的,但我不认为这个问题——不幸的是,我不是在办公室里,而是说话。

问题回答

页: 1 发送人:CurrentDispader into Application.Current.Displa/code>.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...