Expanding on Josh's (correct) answer. Here's the PInvoke signature for that method.
public partial class NativeMethods {
/// Return Type: BOOL->int
///fBlockIt: BOOL->int
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint="BlockInput")]
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern bool BlockInput([System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] bool fBlockIt) ;
}
public static void BlockInput(TimeSpan span) {
try {
NativeMethods.BlockInput(true);
Thread.Sleep(span);
} finally {
NativeMethods.BlockInput(false);
}
}
EDIT
Added some code to demonstrate how to block for an interval
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…