ContextSwitchDeadlock检测在C#中的错误 [英] ContextSwitchDeadlock Was Detected error in C#

查看:525
本文介绍了ContextSwitchDeadlock检测在C#中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行C#应用程序,并在运行时我得到以下错误:

I am running a C# application, and during run-time I get the following error:

在CLR一直无法从COM上下文0x20e480过渡到COM环境0x20e5f0 60秒。拥有目标上下文/公寓线程是最有可能要么做一个非抽水等待或处理一个很长的运行操作,而抽水Windows消息。这种情况一般具有性能产生负面影响,甚至可能导致应用程序变得无响应或内存使用量随着时间的推移不断积累。为了避免这个问题,所有单线程单元(STA)线程应该使用抽水等待原语(如CoWaitForMultipleHandles),并在长时间运行的操作常规泵的消息。

The CLR has been unable to transition from COM context 0x20e480 to COM context 0x20e5f0 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.

任何人都可以请帮我这儿有问题?

Can anyone please help me out with the problem here?

非常感谢。

推荐答案

你的程序的主线程一直忙于执行code一分钟。它不是利用其正常职责的照顾,抽消息循环。当你在一个工作线程使用COM服务器是非法的:调用他们的方法不能出动,直到你的主线程再次进入空闲状态

The main thread of your program has been busy executing code for a minute. It is not taking care of its normal duties, pumping the message loop. That's illegal when you use COM servers in a worker thread: calls to their methods cannot be dispatched until your main thread goes idle again.

这应该是容易看见的,你的用户界面应该是死定了大门钉。窗户应该与显示没有响应鬼更换你的主窗口。关闭窗口将无法正常工作,没有点击事件有任何影响。

It should be readily visible, your UI should be dead as a door nail. Windows should have replaced your main window with a ghost that displays "Not Responding". Closing the window won't work, no click events have any effect.

无论你的主线程正在做应该由一个工作线程来完成吧。在的BackgroundWorker 类是好为,你会发现在MSDN Library文章为它在许多使用帮助。使用debug +打破一切,调试+的Windows +线程,如果你不知道什么主线程在做什么。

Whatever your main thread is doing should be done by a worker thread instead. The BackgroundWorker class is good for that, you'll find many usage help in the MSDN Library article for it. Use Debug + Break All, Debug + Windows + Threads if you have no idea what the main thread is doing.

还有一个可能的原因:一定要安装Service Pack 1,如果你正在使用VS2005的RTM版

One more possible cause: be sure to install service pack 1 if you are using the RTM version of VS2005.

这篇关于ContextSwitchDeadlock检测在C#中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆