0
我打電話給BroadcastSystemMessage
方法從User32.dll
。在一臺PC(Windows8 Pro)上調用該方法,但調用永遠不會結束。應用程序正在等待,但結果(也不例外)從不返回。我在幾臺Windows8電腦(不同硬件,有/沒有殺毒軟件等)上試過,但這種行爲在這些電腦上從未發生過。BroadcastSystemMessage呼叫永不完成
目標計算機沒有任何已安裝或正在運行的應用程序,它將註冊自定義消息。所以所有的應用程序應該忽略廣播。
此行爲是否正確?我沒有在MSDN上看到任何關於它的提及。 有什麼問題?有一些正確的方法可以在超時後停止呼叫嗎?
歡迎任何建議或提示。
的代碼是:
[DllImport("user32", SetLastError = true)]
public static extern int BroadcastSystemMessage(MessageBroadcastFlags flags, ref MessageBroadcastRecipients lpInfo, uint Msg, IntPtr wParam, IntPtr lParam);
// ......
BroadcastSystemMessage(
MessageBroadcastFlags.BSF_IGNORECURRENTTASK, // do not send message to this process
ref MessageBroadcastRecipients.BSM_ALLDESKTOPS, // broadcast recipients
msg, // registered private message
IntPtr.Zero, // message-specific value
IntPtr.Zero);
// ......
[Flags]
public enum MessageBroadcastFlags : uint {
BSF_QUERY = 0x00000001,
BSF_IGNORECURRENTTASK = 0x00000002,
BSF_FLUSHDISK = 0x00000004,
BSF_NOHANG = 0x00000008,
BSF_POSTMESSAGE = 0x00000010,
BSF_FORCEIFHUNG = 0x00000020,
BSF_NOTIMEOUTIFNOTHUNG = 0x00000040,
BSF_ALLOWSFW = 0x00000080,
BSF_SENDNOTIFYMESSAGE = 0x00000100,
BSF_RETURNHDESK = 0x00000200,
BSF_LUID = 0x00000400
}
[Flags]
public enum MessageBroadcastRecipients : uint {
BSM_ALLCOMPONENTS = 0x00000000,
BSM_VXDS = 0x00000001,
BSM_NETDRIVER = 0x00000002,
BSM_INSTALLABLEDRIVERS = 0x00000004,
BSM_APPLICATIONS = 0x00000008,
BSM_ALLDESKTOPS = 0x00000010
}
這有點像在溫布利體育場內與十萬個嘈雜的球迷大吼一聲,希望他們都會迴應。只需要注意一下比賽而不是你來阻止其工作。具體說一下你所嚷嚷的人,期望他們仍然無視你。 –