public AccurateTimer(Action action, int delay) { this.mAction = action; AccurateTimer.timeBeginPeriod(1); this.mHandler = new AccurateTimer.TimerEventDel(this.TimerCallback); this.mTimerId = AccurateTimer.timeSetEvent(delay, 0, this.mHandler, IntPtr.Zero, 1); }
private void Connect() { Console.WriteLine("Connect"); try { /// The constructor is similar to SimConnect_Open in the native API m_oSimConnect = new SimConnect("Simconnect - Simvar test", m_hWnd, WM_USER_SIMCONNECT, null, bFSXcompatible? (uint)1 : 0); /// Listen to connect and quit msgs m_oSimConnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(SimConnect_OnRecvOpen); m_oSimConnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(SimConnect_OnRecvQuit); /// Listen to exceptions m_oSimConnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(SimConnect_OnRecvException); /// Catch a simobject data request m_oSimConnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(SimConnect_OnRecvSimobjectDataBytype); LoadItems(); int delay = 1; gameTimer = new AccurateTimer(new Action(TimerTick1), delay); } catch (COMException ex) { Console.WriteLine("Connection to KH failed: " + ex.Message); } }
public void Stop() { AccurateTimer.timeKillEvent(this.mTimerId); AccurateTimer.timeEndPeriod(1); Thread.Sleep(100); }