public bool Connect() { if (_simConnect == null) { try { ChangeConnectionState?.Invoke(CONNECTION_STATE.Connecting); _simConnect = new SimConnect("FSX Plane Tracer", (IntPtr)0, 0, _simconnectReady, 0); SetupEventHandlers(); SetupPulling(); _simconnectReciveMessageCancelTokenSource = new CancellationTokenSource(); Task.Factory.StartNew(() => { SimconnectReciveMessage(_simconnectReciveMessageCancelTokenSource.Token); }, _simconnectReciveMessageCancelTokenSource.Token); return(true); } catch (COMException) { return(false); } } else { return(true); } }
public void Disconnect() { if (_simConnect != null) { _simconnectReciveMessageCancelTokenSource.Cancel(); _simConnect.UnsubscribeFromSystemEvent(SIMCONNECT_DATA_DEFINITION_ID.planeLocation); ChangeConnectionState?.Invoke(CONNECTION_STATE.Disconnected); _simConnect.Dispose(); _simConnect = null; } }
private FSXConnectionManager() { ChangeConnectionState?.Invoke(CONNECTION_STATE.Disconnected); }
private void SimconnectOnRecvOpen(SimConnect sender, SIMCONNECT_RECV_OPEN data) { ChangeConnectionState?.Invoke(CONNECTION_STATE.Connected); }