예제 #1
0
        private void Connect()
        {
            if (simConnectManager == null)
            {
                simConnectManager = new SimConnectManager(this.Handle);
            }

            // подписываемся на соответствующие события
            simConnectManager.ConnectedEvent        += SimConnectManager_ConnectedEvent;
            simConnectManager.DisconnectedEvent     += SimConnectManager_DisconnectedEvent;
            simConnectManager.UnknownRequestIDEvent += SimConnectManager_UnknownRequestIDEvent;
            simConnectManager.ReceivedDataEvent     += SimConnectManager_ReceivedDataEvent;

            simConnectManager.Connect();
            sw.Start();
        }
예제 #2
0
        private void Disconnect()
        {
            if (simConnectManager != null)
            {
                MainTimer.Enabled  = false;
                StopButton.Enabled = false;

                simConnectManager.CloseConnection();

                // отписываемся от событий на которые раннее были подписаны
                simConnectManager.ConnectedEvent        -= SimConnectManager_ConnectedEvent;
                simConnectManager.DisconnectedEvent     -= SimConnectManager_DisconnectedEvent;
                simConnectManager.UnknownRequestIDEvent -= SimConnectManager_UnknownRequestIDEvent;
                simConnectManager.ReceivedDataEvent     -= SimConnectManager_ReceivedDataEvent;

                simConnectManager.Dispose();
                simConnectManager = null;

                displayText("Connection closed");
                sw.Stop();
            }
        }