2011-04-06 49 views
0

我有一个WPF图表应用程序。基本上,用户从文件输入数据,应用程序对数据进行图表。当点的图表中的数量变得非常大,我得到的是说WPF密集UI处理导致ContextSwitchDeadlock

The CLR has been unable to transition from COM context 0x23cda8 to COM context 0x23cf18 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

现在ContextSwitchDeadlock错误,我意识到这是因为UI线程不应该是忙不过来长,但我不清楚我的选择是什么,因为整个时间都花在向用户界面添加组件。如果我经常访问UI元素,我不能使用BackGroundWorker。那么我该从哪里出发?

+0

我对WPF不是很熟悉,但是从这个消息我认为将'STAThread'改为'MTAThread'应该可以做到。 – Aidiakapi 2011-04-06 06:08:22

+0

调用Thread.Join(0)在您长时间运行的任务中的某处,以允许消息泵送 – adrianm 2011-04-06 08:51:29

回答

-3

有这么多的视觉效果真的很实际吗?如果是这样,我会打破添加视觉效果,并在单独的消息中做每一个。换句话说,使用Dispatcher将消息与适当的DispatcherPriority进行排队。每条消息将负责从总数中添加一小部分视觉效果。

+0

您是什么意思?我还有其他选择吗? – Aks 2011-04-06 07:46:44

+0

我的意思是什么可能需要许多视觉效果?也许有可能你可以将许多视觉效果合并成一个视觉效果 - 你需要详细说明你的具体情况才能确定这一点。 – 2011-04-06 17:17:25

+0

答案“它真的很实际”在这里没有解决任何问题。 – Akku 2012-03-07 15:53:59