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

问题描述

我要打电话 WaitHandle.WaitOne(时间跨度)在.net中,但我STA线程并将其泵的消息,同时等待。其原因是超出了这个问题的范围,我需要等待的没有的抽。我怎么能等待WaitHandle的是没有抽的消息信号?

这似乎在某些情况下是 WaitHandle.WaitOne 不抽取消息。但它确实有时一些消息。查看这些链接了解更多信息:

  1. 托管和非托管线程在Microsoft Windows
  2. 管阻塞
解决方案

的WaitForSingleObject或WaitForMultipleObjects是不抽的等待;用的P / Invoke。

  [的DllImport(kernel32中,SetLastError = TRUE,ExactSpelling =真)
公共静态外部的Int32 WaitForSingleObject的(SafeWaitHandle手柄,的Int32毫秒);
 

-Oisin

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?

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