【发布时间】:2011-08-03 17:35:40
【问题描述】:
这是一个 C# 应用程序,它作为通知图标位于托盘中并执行其操作,直到有人右键单击它并选择关闭(菜单选项),或者它从外部应用程序或操作系统获取 wm_close,例如在重新启动期间.
protected override void WndProc(ref Message m)
{
case Win32.WmClose:
//recvd message to shutdown
Program.Log.InfoFormat("Shutdown received at {0}", DateTime.Now);
CleanUp();
this.Close(); //this is the main form
break;
//other case statements here
}
//somewhere else on menu exit of notify icon
private void toolStripMenuItemExit_Click(object sender, EventArgs e)
{
Program.Log.InfoFormat("Manual EXIT at {0}", DateTime.Now);
CleanUp();
this.Close(); //this is the main form
}
this.close() 触发另一个 WM_CLOSE 发送应用程序。处理这种情况的正确方法是什么?谢谢你
【问题讨论】:
-
Udpdate:或者调用 Application.exit 以防 Wmclose 而不是 form.close() 也解决了这个问题。仅供参考。
标签: c# winapi c#-4.0 c#-3.0 pinvoke