【发布时间】:2011-01-28 15:51:40
【问题描述】:
MSDN 说 System.Windows.Application 的公共静态成员是线程安全的。但是当我尝试使用多个线程运行我的应用程序时,出现以下异常:
ArgumentException: An entry with the same key already exists.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.SortedList`2.Add(TKey key, TValue value)
at System.IO.Packaging.Package.AddIfNoPrefixCollisionDetected(ValidatedPartUri partUri,
PackagePart part)
at System.IO.Packaging.Package.GetPartHelper(Uri partUri)
at System.IO.Packaging.Package.GetPart(Uri partUri)
at System.Windows.Application.GetResourceOrContentPart(Uri uri)
at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean
bSkipJournaledProperties)
at System.Windows.Application.LoadComponent(Uri resourceLocator)
异常发生在以下调用中:
genericResources = (ResourceDictionary)Application.LoadComponent(new Uri("/Themes/Generic.xaml", UriKind.Relative));
该应用程序在单个线程甚至两个或三个线程上都可以正常工作。当我起床超过 5 点时,我每次都会收到错误消息。难道我做错了什么?我该怎么做才能解决这个问题?
【问题讨论】:
-
添加了 C# 标签...应该引起您的更多关注。
-
真好。 .NET 4.5 中似乎没有修复。在connect.microsoft.com/VisualStudio/feedback/details/758055/… 创建了一个连接问题。
标签: c# wpf multithreading thread-safety