另一种解决方案是使用PostMessage win API调用而不是SendMessage,下面是一个对我来说效果很好的示例(我使用的是winXP sp3):
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.Dll")]
public static extern int PostMessage(IntPtr hWnd, UInt32 msg, int wParam, int lParam);
private const UInt32 WM_CLOSE = 0x0010;
...
IntPtr hWnd = FindWindow("ExploreWClass", null);
if (hWnd.ToInt32()!=0) PostMessage(hWnd, WM_CLOSE, 0, 0);
PostMessage和SendMessage api调用之间的区别如下所述:
http://msdn.microsoft.com/en-us/magazine/cc301431.aspx