3
我有一个WPF应用程序,并且在不同的线程中运行一些动画,所以我的主UI线程将会响应。我正在使用的代码发布here:在另一个线程中创建WPF窗口时出现异常
Thread thread = new Thread(() =>
{
Window1 w = new Window1();
w.Show();
w.Closed += (sender2, e2) => w.Dispatcher.InvokeShutdown();
System.Windows.Threading.Dispatcher.Run();
});
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
它通常工作正常,但系统部署后,我提出投诉应用程序崩溃与下面的堆栈跟踪:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.Generic.List`1.RemoveAt(Int32 index)
at System.IO.Packaging.PackagePart.CleanUpRequestedStreamsList()
at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access)
at System.IO.Packaging.PackagePart.GetStream()
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at Window1.xaml:line 1
at Window1..ctor()
有没有人见过这个例外之前,可以解释那里发生了什么?什么可能是这个具体例外的原因?
我正在使用.Net 3.5 SP1
听起来像一个解决方案:-)你有任何额外的参考备份这个假设?我无法测试它,因为它只发生过一次... – 2012-04-10 13:33:13
不,这只是一个想法。你可以看看System.Windows.Application.LoadComponent的代码来找到那里的线程安全问题。或者你可以尝试用测试来强调测试LoadComponent,在不同的线程上同时创建多个窗口来重现此bug – Nikolay 2012-04-10 14:57:39
好的,谢谢。我会看看它 - 我鼓励你,并且会接受这个答案,当我确定它是我所遇到的异常的真正根源。 – 2012-04-12 12:16:40