static void StartService() { SQL.Init(); Core CoreInSer = new Core(); AsServer Server = new AsServer(IPAddress.Any, 5000); ComPortListener ComPotrList = new ComPortListener(); WinLog.Init(); CoreInSer.Start(); Thread ServerThread = new Thread(Server.Start); ServerThread.IsBackground = true; ServerThread.Start(); Thread CPList = new Thread(ComPotrList.OpenCom); CPList.IsBackground = true; CPList.Start(); CoreInSer.UpdateClient(); }
static void Main(string[] args) { SQL.Init(); Core CoreInSer = new Core(); // TODO: Настройки вынести в отдельный конфигурационный файл AsServer Server = new AsServer(IPAddress.Any, 5000); ComPortListener ComPotrList = new ComPortListener(); WinLog.Init(); CoreInSer.Start(); Thread ServerThread = new Thread(Server.Start); ServerThread.IsBackground = true; ServerThread.Start(); Thread CPList = new Thread(ComPotrList.OpenCom); CPList.IsBackground = true; CPList.Start(); CoreInSer.UpdateClient(); Console.WriteLine("Server started"); Console.WriteLine("OK"); Console.ReadLine(); }
/*private static void ProcessAddQueue() * { * while ( m_AddQueue.Count != 0 ) * { * Timer t = (Timer)m_AddQueue.Dequeue(); * t.m_Next = DateTime.Now + t.m_Delay; * t.m_Index = 0; * m_Timers[(int)t.Priority].Add( t ); * }//while !empty * } * * private static void ProcessRemoveQueue() * { * while ( m_RemoveQueue.Count != 0 ) * { * Timer t = (Timer)m_RemoveQueue.Dequeue(); * m_Timers[(int)t.Priority].Remove( t ); * }//while !empty * } * * private static void ProcessPriorityQueue() * { * while ( m_PriQueue.Count != 0 ) * { * PriChangeEntry e = (PriChangeEntry)m_PriQueue.Dequeue(); * * Timer t = e.m_Timer; * TimerPriority oldPri = e.m_OldPri; * * m_Timers[(int)oldPri].Remove( t ); * m_Timers[(int)t.Priority].Add( t ); * * e.Free(); * }//while !empty * }*/ public void TimerMain() { DateTime now; int i, j; while (!Core.Closing) { now = DateTime.UtcNow; /*ProcessAddQueue(); * ProcessRemoveQueue(); * ProcessPriorityQueue();*/ lock (m_ChangeQueue.SyncRoot) ProcessChangeQueue(now); bool queued = false; for (i = 0; i < m_Timers.Length; i++) { if (now < m_NextPriorities[i]) { break; } m_NextPriorities[i] = now + m_PriorityDelays[i]; for (j = 0; j < m_Timers[i].Count; j++) { Timer t = (Timer)m_Timers[i][j]; if (!t.m_Queued && now > t.m_Next) { t.m_Queued = true; lock (m_Queue) m_Queue.Enqueue(t); queued = true; if (t.m_Count != 0 && (++t.m_Index >= t.m_Count)) { t.Stop(); } else { t.m_Next = now + t.m_Interval; } } } //for timers.Count } //for Timer.Timers.Length /* notify the core of new timers in the queue */ if (queued) { Core.WakeUp(); } /* find the earliest timer class which needs another check */ DateTime earliest = DateTime.MaxValue; for (i = 0; i < m_Timers.Length; i++) { if (m_Timers[i].Count > 0 && m_NextPriorities[i] < earliest) { earliest = m_NextPriorities[i]; } } /* sleep until there is a signal or until the next * timer must be activated */ now = DateTime.UtcNow; TimeSpan sleep = earliest <= now ? TimeSpan.FromMilliseconds(10) : (earliest == DateTime.MaxValue ? TimeSpan.FromSeconds(1) : earliest - now); m_Signal.WaitOne(sleep, false); //Thread.Sleep(sleep); //Thread.Sleep(10); } //while (true) } //TimerMain