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

问题描述

我想在 .NET 中调用 WaitHandle.WaitOne(TimeSpan),但我在 STA 线程上,它在等待时会发送消息.由于超出此问题范围的原因,我需要等待抽水.如何在不发送消息的情况下等待 WaitHandle 发出信号?

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. Microsoft Windows 中的托管和非托管线程
  2. 托管屏蔽

推荐答案

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);

-奥辛

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

07-10 03:17