在主UI线程中声明后,CollectionView不会从后台工作线程更新?

时间:2014-10-18 11:32:18

标签: c# multithreading backgroundworker observablecollection

我正在使用后台工作线程和Observable集合。问题是我在主线程中声明属性如下:

 public ObservableCollection<IpMacAddressClass> ipmac { get; set; }

但我需要在后台工作人员DoWork流程下更新此集合。现在它给了我以下错误:

This type of CollectionView does not support changes to its SourceCollection from a 
thread different from the Dispatcher thread.

我的代码如下:

var item = new IpMacAddressClass();
string pattern = @"(F8-F7-D3-00\S+)";
Match matchmac = Regex.Match(_stringData, pattern);

string pattern2 = @"(192.168.1\S+)";
Match matchip = Regex.Match(_stringData, pattern2);

while (matchmac.Success && matchip.Success)
{
    item._ip = matchip.Value;
    Console.WriteLine("IP Address : {0}", matchip.Value);
    item._mac = matchmac.Value;
    Console.WriteLine("MAC Address : {0}", matchmac.Value);

    matchmac = matchmac.NextMatch();
    matchip = matchip.NextMatch();
    ***ipmac.Add(item);***
}

我想知道如何解决这个问题。任何帮助都会非常明显。

0 个答案:

没有答案