本文介绍了如何等待WaitHandle没有消息泵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在.NET中调用 WaitHandle.WaitOne(TimeSpan),但我在STA线程,它在等待时泵消息。由于超出此问题范围的原因,我需要等待,无需泵送。

I want to call WaitHandle.WaitOne(TimeSpan) in .NET, but I'm on the STA thread and it pumps messages while waiting. For reasons that are beyond the scope of this question, I need to wait without pumping. How can I wait for a WaitHandle to be signaled without pumping messages?

在某些情况下,似乎 WaitHandle.WaitOne 不泵浦消息。但它有时为某些消息。有关详情,请参阅以下链接:

It seems in some scenarios that WaitHandle.WaitOne does not pump messages. But it does sometimes for some messages. See these links for more information on that:




  1. Managed and Unmanaged Threading in Microsoft Windows
  2. Managed blocking


推荐答案

WaitForSingleObject或WaitForMultipleObjects是非抽象等待;使用p / invoke。

WaitForSingleObject or WaitForMultipleObjects are non-pumping waits; use p/invoke.

[DllImport("kernel32", SetLastError=true, ExactSpelling=true)]
public static extern Int32 WaitForSingleObject(SafeWaitHandle handle, Int32 milliseconds);

-Oisin

这篇关于如何等待WaitHandle没有消息泵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 09:54