Здравствуйте, danclax, Вы писали:
D>Да точно, PostMessage лучше — без блокировки. Но я тут обратил внимание на раздел — .NET. А PostMessage/SendMessage — WinAPI. Навскидку способа в .NET не удалось найти.
Вручную (подсмотрено в System.Windows.Forms):
[SuppressUnmanagedCodeSecurity]
internal static class UnsafeNativeMethods
{
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr PostMessage(HandleRef hwnd, int msg, int wparam, int lparam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr PostMessage(HandleRef hwnd, int msg, int wparam, IntPtr lparam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern bool PostMessage(HandleRef hwnd, int msg, IntPtr wparam, IntPtr lparam);
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern void PostQuitMessage(int nExitCode);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int PostThreadMessage(int id, int msg, IntPtr wparam, IntPtr lparam);
}