003c9f8fb32c08f55460117e8948eb6960007c82.svn-base 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.IO;
  6. using System.Threading;
  7. namespace Core.Mes.ServerManager
  8. {
  9. public class ExitMessageFilter : System.Windows.Forms.IMessageFilter
  10. {
  11. private FrmSeverMain frm;
  12. public ExitMessageFilter(FrmSeverMain frm)
  13. {
  14. this.frm = frm;
  15. }
  16. #region IMessageFilter 成员
  17. public bool PreFilterMessage(ref Message m)
  18. {
  19. if (frm == null)
  20. {
  21. }
  22. if (m.Msg == 16)
  23. {
  24. ApplicationExit();
  25. Thread.Sleep(2 * 1000);
  26. }
  27. return false;
  28. }
  29. #endregion
  30. private static void ApplicationExit()
  31. {
  32. string path = string.Format(@"{0}/log/Application/{1}.txt", Application.StartupPath, System.DateTime.Now.ToString("yyyy_MM_dd"));
  33. using (StreamWriter sw = new StreamWriter(path, true, Encoding.UTF8))
  34. {
  35. StringBuilder sbtxt = new StringBuilder();
  36. sbtxt.AppendLine("==============================================");
  37. sbtxt.AppendLine("从任务管理器中关闭服务");
  38. sbtxt.AppendLine(string.Format("服务关闭时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm::ss")));
  39. sbtxt.AppendLine("==============================================");
  40. sw.WriteLine(sbtxt.ToString());
  41. }
  42. }
  43. }
  44. }