using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.IO; using System.Text; using System.Diagnostics; using System.Collections; using System.Data.SqlClient; using System.Timers; using System.Threading; using System.Runtime.InteropServices; namespace BEMSDataGateway { static class Program { /// /// 해당 응용 프로그램의 주 진입점입니다. /// /// [STAThread] static void Main() { string mtxName = "DGW"; Mutex mtx = new Mutex(true, mtxName); // 1초 동안 뮤텍스를 획득하려 대기 TimeSpan tsWait = new TimeSpan(0, 0, 1); bool success = mtx.WaitOne(tsWait); if (!success) { MessageBox.Show("프로그램이 이미 실행중입니다."); return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } /// /// 타이머 스레드 클래스 /// class My_TimerThread { static string TimeCheck = ""; Parsing PS = new Parsing(); Control_Point_Group CPG = new Control_Point_Group(); public System.Timers.Timer timer2; private Object DBCommObj = new Object(); public static bool check = false; public void timer2start() { timer2 = new System.Timers.Timer(); timer2.Interval = 10 * 1000; // 10sec 간격 timer2.Elapsed += new ElapsedEventHandler(timer2_Elapsed); timer2.Start(); } public void timer2Stop() { timer2.Stop(); timer2.Enabled = false; timer2.Dispose(); } public void timer2_Elapsed(object sender, ElapsedEventArgs e) // 1분마다 실행되는 데이터 수집 로직 { string tmpMin = DateTime.Now.Minute.ToString(); // 현재의 '분' lock (DBCommObj) { if (TimeCheck != tmpMin) { CPG.Control_Group(); CPG.Control_Point(); TimeCheck = PS.SettingFileParsing(); } } } } }