b06aae07e318a092a9efdbd9d2cd4b01e3f6fc20.svn-base 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. System.Timers.Timer timer2 = new System.Timers.Timer();
  48. public static bool check = false;
  49. public void timer2start()
  50. {
  51. timer2.Interval = 2000; // 2sec 간격
  52. timer2.Elapsed += new ElapsedEventHandler(timer2_Elapsed);
  53. timer2.Start();
  54. }
  55. public void timer2Stop()
  56. {
  57. timer2.Stop();
  58. timer2.Enabled = false;
  59. }
  60. public void timer2_Elapsed(object sender, ElapsedEventArgs e) // 1분마다 실행되는 데이터 수집 로직
  61. {
  62. string tmpMin = DateTime.Now.Minute.ToString(); // 현재의 '분'
  63. if ((TimeCheck != tmpMin) && check == false)
  64. {
  65. check = true;
  66. CPG.Control_Group();
  67. CPG.Control_Point();
  68. TimeCheck = PS.SettingFileParsing();
  69. check = false;
  70. }
  71. }
  72. }
  73. }