Global.asax 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <%@ Application Language="C#" %>
  2. <%@ Import Namespace="Curtain.DataAccess" %>
  3. <%@ Import Namespace="Curtain.Log" %>
  4. <%@ Import Namespace="DK.XuWei.WebMes" %>
  5. <script RunAt="server">
  6. // 定时器
  7. System.Timers.Timer tr = null;
  8. void Application_Start(object sender, EventArgs e)
  9. {
  10. // 在应用程序启动时运行的代码
  11. string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  12. DataAccess.DefaultParameterType = SQLParameterType.CDA;
  13. DataAccess.DefaultDataBaseType = Curtain.DataAccess.DataBaseType.Oracle;
  14. DataAccess.DefaultConnectionString = connStr;
  15. // 设置定时器
  16. tr_Load();
  17. }
  18. /// <summary>
  19. /// 设置定时器
  20. /// </summary>
  21. void tr_Load()
  22. {
  23. Logger.Debug("$$$定时器已启动$$$");
  24. //设置timer
  25. tr = new System.Timers.Timer(180000);
  26. tr.Elapsed += new System.Timers.ElapsedEventHandler(tr_Timer);
  27. tr.Enabled = true;
  28. tr.AutoReset = true;
  29. }
  30. /// <summary>
  31. /// 定时器要执行的任务
  32. /// </summary>
  33. /// <param name="sender"></param>
  34. /// <param name="e"></param>
  35. void tr_Timer(object sender, EventArgs e)
  36. {
  37. // 发送数据到LED
  38. Led.SendData();
  39. }
  40. void Application_End(object sender, EventArgs e)
  41. {
  42. // 在应用程序关闭时运行的代码
  43. Logger.Debug("$$$定时器被关闭$$$");
  44. if (tr != null)
  45. {
  46. tr.Dispose();
  47. }
  48. // 重新唤醒当前应用
  49. ReworkHttp.Rework();
  50. }
  51. void Application_Error(object sender, EventArgs e)
  52. {
  53. // 在出现未处理的错误时运行的代码
  54. Exception error = Server.GetLastError().GetBaseException();
  55. if (error != null)
  56. {
  57. //记录日志
  58. Logger.Error(error);
  59. //输出错误信息
  60. //2022-11-15 冯林勇 出现错误不弹出日志
  61. //HttpContext.Current.Response.Write(new JsonResult(JsonStatus.otherError).ToJson());
  62. //2022-11-15 冯林勇 出现错误不弹出日志
  63. }
  64. Server.ClearError();
  65. }
  66. void Session_Start(object sender, EventArgs e)
  67. {
  68. // 在新会话启动时运行的代码
  69. }
  70. void Session_End(object sender, EventArgs e)
  71. {
  72. // 在会话结束时运行的代码。
  73. // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
  74. // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
  75. // 或 SQLServer,则不引发该事件。
  76. }
  77. </script>