gpt4 book ai didi

c# - 在长时间操作期间抽取 Windows 消息?

转载 作者:IT王子 更新时间:2023-10-29 04:30:37 25 4
gpt4 key购买 nike

我在执行一项大型操作时收到以下消息:

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

如何发送 Windows 消息,以便在长时间操作时不再发生此错误?

最佳答案

不清楚上下文到底是什么 - 您是否在 WinForms 或 WPF 应用程序的 UI 线程上执行一些长时间运行的任务?如果是这样,请不要这样做 - 使用 BackgroundWorker,或者直接在线程池或新线程上运行任务(可能使用 Control.Invoke/BeginInvokeDispatcher 如果您需要更新 UI)。如果您的大型操作使用提示的 COM 组件,它会更难...

关于c# - 在长时间操作期间抽取 Windows 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4806742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com