Program.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. using System.IO;
  6. using System.Text;
  7. using System.Diagnostics;
  8. using System.Collections;
  9. using System.Data.SqlClient;
  10. using System.Timers;
  11. using System.Threading;
  12. using System.Runtime.InteropServices;
  13. namespace BEMSDataGateway
  14. {
  15. static class Program
  16. {
  17. /// <summary>
  18. /// 해당 응용 프로그램의 주 진입점입니다.
  19. /// </summary>
  20. ///
  21. [STAThread]
  22. static void Main()
  23. {
  24. string mtxName = "DGW";
  25. Mutex mtx = new Mutex(true, mtxName);
  26. // 1초 동안 뮤텍스를 획득하려 대기
  27. TimeSpan tsWait = new TimeSpan(0, 0, 1);
  28. bool success = mtx.WaitOne(tsWait);
  29. if (!success)
  30. {
  31. MessageBox.Show("프로그램이 이미 실행중입니다.");
  32. return;
  33. }
  34. Application.EnableVisualStyles();
  35. Application.SetCompatibleTextRenderingDefault(false);
  36. Application.Run(new Form1());
  37. }
  38. }
  39. /// <summary>
  40. /// 타이머 스레드 클래스
  41. /// </summary>
  42. class My_TimerThread
  43. {
  44. static string TimeCheck = "";
  45. Parsing PS = new Parsing();
  46. Control_Point_Group CPG = new Control_Point_Group();
  47. public System.Timers.Timer timer2;
  48. private Object DBCommObj = new Object();
  49. public static bool check = false;
  50. public void timer2start()
  51. {
  52. timer2 = new System.Timers.Timer();
  53. timer2.Interval = 10 * 1000; // 10sec 간격
  54. timer2.Elapsed += new ElapsedEventHandler(timer2_Elapsed);
  55. timer2.Start();
  56. }
  57. public void timer2Stop()
  58. {
  59. timer2.Stop();
  60. timer2.Enabled = false;
  61. timer2.Dispose();
  62. }
  63. public void timer2_Elapsed(object sender, ElapsedEventArgs e) // 1분마다 실행되는 데이터 수집 로직
  64. {
  65. string tmpMin = DateTime.Now.Minute.ToString(); // 현재의 '분'
  66. lock (DBCommObj)
  67. {
  68. if (TimeCheck != tmpMin)
  69. {
  70. CPG.Control_Group();
  71. CPG.Control_Point();
  72. TimeCheck = PS.SettingFileParsing();
  73. }
  74. }
  75. }
  76. }
  77. }