试图从另一个线程访问静态ConcurrentDictionary

时间:2018-03-09 21:38:17

标签: c# .net multithreading

我收到了以下错误:

PresentationFramework.dll中出现未处理的“System.Windows.Markup.XamlParseException”类型异常 附加信息:必须在与DependencyObject相同的Thread上创建DependencySource。

当我试图访问静态ConcurrentDictionary时:

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

来自另一个线程:

public static class Client
{
    public static ConcurrentDictionary<string, ImageBrush> ChannelMemberList { get; set; }
}

P.S。我尝试复制这个对象。我认为这是因为参考静态对象

1 个答案:

答案 0 :(得分:0)

您是否尝试将作业包裹在PARTITIONED BY

Dispatcher

基本上Dispatcher.CurrentDispatcher.Invoke(() => this.ChannelMemberList = new Dictionary<string, ImageBrush>(Client.ChannelMemberList);); 是一个&#34;调解员&#34;你的UI线程和后台线程之间,以及上面的调用,你要求它让两个线程进行通信。