這是一個C#應用程序,作爲notifyicon坐在托盤中,並執行其任務,直到有人右鍵單擊它並選擇關閉(菜單選項)或它獲取來自外部應用程序或操作系統的wm_close在重啓過程中表示。如何檢測區分外部wm_close與內部由form.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在tailspin中發送應用程序。處理這種情況的正確方法是什麼?謝謝
Udpdate:或者在Wmclose而不是form.close()的情況下調用Application.exit也可以解決此問題。僅供參考。 – Gullu