public void CloseConnection() { try { if (simconnect != null) { simconnect.UnsubscribeFromSystemEvent(EVENTS.SIM_START); simconnect.UnsubscribeFromSystemEvent(EVENTS.SIM_STOP); simconnect.UnsubscribeFromSystemEvent(EVENTS.PAUSED); simconnect.UnsubscribeFromSystemEvent(EVENTS.AIRCRAFT_LOADED); simconnect.UnsubscribeFromSystemEvent(EVENTS.FLIGHT_LOADED); simconnect.UnsubscribeFromSystemEvent(EVENTS.CRASHED); simconnect.UnsubscribeFromSystemEvent(EVENTS.CRASH_RESET); simconnect.UnsubscribeFromSystemEvent(EVENTS.FLIGHTPLAN_ACTIVATED); simconnect.UnsubscribeFromSystemEvent(EVENTS.FLIGHTPLAN_DEACTIVATED); simconnect.UnsubscribeFromSystemEvent(EVENTS.POSITION_CHANGED); simconnect.UnsubscribeToFacilities(SIMCONNECT_FACILITY_LIST_TYPE.AIRPORT); // Dispose serves the same purpose as SimConnect_Close() simconnect.Dispose(); simconnect = null; } } catch (Exception ex) { logger.LogWarning($"Cannot unsubscribe events! Error: {ex.Message}"); } }
private void closeConnection() { if (simconnect != null) { // Unsubscribe from all the system events simconnect.UnsubscribeFromSystemEvent(EVENTS.SIMSTART); simconnect.UnsubscribeFromSystemEvent(EVENTS.SIMSTOP); // Dispose serves the same purpose as SimConnect_Close() simconnect.Dispose(); simconnect = null; } }
public void DisconnectSim() { if (simconnect != null) { OnFSConnectionStatusChanged(false); if (!simExited) { simconnect.UnsubscribeFromSystemEvent(EVENTS.SIM_START); simconnect.UnsubscribeFromSystemEvent(EVENTS.SIM_STOP); simconnect.UnsubscribeFromSystemEvent(EVENTS.FLIGHTPLAN_LOADED); simconnect.UnsubscribeFromSystemEvent(EVENTS.FLIGHTPLAN_DIACTIVATED); } simconnect.Dispose(); simconnect = null; } SimConnected = false; }
public void disconnect() { if (simconnect != null) { simconnect.UnsubscribeFromSystemEvent(EVENTS.EVENT_1S); simconnect.Dispose(); simconnect = null; } FSXConnectionChanged(); }
//release our simconnect object private void closeFocusGrab() { if (simconnect != null) { try //The application may have been shut down and this will throw { simconnect.UnsubscribeFromSystemEvent(Event.MISSION_END); simconnect.Dispose(); } catch //do nothing here we are closing simconnect after this. {} simconnect = null; } }