检测到 DisconnectedContext/ContextSwitch 死锁

发布于 2024-11-06 22:51:33 字数 653 浏览 0 评论 0原文

我有 RichTextBox,我从多线程进行大量消息记录。 一段时间后,我第一次收到“检测到 DisconnectedContext”消息,并从“调试”->“异常...”窗口中删除了中断异常。但后来我收到“检测到 ContextSwitchDeadlock”。我也删除了它,用户界面又恢复了生机。 过了一段时间,又结冰了。

有办法防止这种情况吗?或者是否有一个组件支持着色、更改字体以在 .NET 中提供视觉反馈(如 RichTextBox),但不会出现此错误?

检测到 ContextSwitchDeadlock
消息: CLR 无法 从 COM 上下文 0x6eb0760 的转换 到 COM 上下文 0x6eb08d0 为 60 秒。拥有该线程的线程 目的地环境/公寓是最 可能要么进行非抽水等待 或处理很长时间的运行 无需泵送 Windows 即可运行 消息。这种情况一般有 负面的性能影响,并可能 甚至导致应用程序变得 无响应或内存使用 随着时间的推移不断积累。到 避免这个问题,全部单身 线程单元 (STA) 线程 应该使用泵等待原语 (例如 CoWaitForMultipleHandles)和 在长时间内定期发送消息 运行操作。

I have RichTextBox which I do heavy message logging from multi threads.
After some time I first received the "DisconnectedContext was detected" message and I removed the breaking on exception from the Debug->Exceptions... window. But then I received "ContextSwitchDeadlock was detected". I removed this too and the UI came back to life.
After some time it freezed again.

Is there a way to prevent this? Or is there a component that supports coloring, changing fonts to give a visual feedback in .NET like RichTextBox but without this error?

ContextSwitchDeadlock was detected
Message: The CLR has been unable to
transition from COM context 0x6eb0760
to COM context 0x6eb08d0 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临风闻羌笛 2024-11-13 22:51:33

您确定要从多个线程更新 RichTextBox 吗?如果是这样,您最好停止它并使用 UI 线程来更新 RTB。为此:调用theForm.BeginInvoke(委托更新RTB的方法)

这应该允许所有并发线程尽快继续,而无需等待响应。

Are you sure you are updating the RichTextBox from multiple threads? If so you'd better stop that and use the UI thread to update the RTB. To do that: call theForm.BeginInvoke( delegate to a method that updates the RTB)

This should allow all the concurrent threads to continue ASAP without waiting for response.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文