private void checkboxAirportSubscription_CheckedChanged(object sender, EventArgs e)
 {
     if (checkboxAirportSubscription.Enabled)
     {
         if (checkboxAirportSubscription.Checked)
         {
             simconnect.SubscribeToFacilities(SIMCONNECT_FACILITY_LIST_TYPE.AIRPORT, DATA_REQUESTS.SUBSCRIBE_REQ);
         }
         else
         {
             simconnect.UnsubscribeToFacilities(SIMCONNECT_FACILITY_LIST_TYPE.AIRPORT);
         }
     }
 }
Example #2
0
        public void CloseConnection()
        {
            try
            {
                cts?.Cancel();
                cts = null;
            }
            catch (Exception ex)
            {
                logger.LogWarning(ex, $"Cannot cancel request loop! Error: {ex.Message}");
            }
            try
            {
                if (simconnect != null)
                {
                    simconnect.UnsubscribeToFacilities(SIMCONNECT_FACILITY_LIST_TYPE.AIRPORT);

                    // Dispose serves the same purpose as SimConnect_Close()
                    simconnect.Dispose();
                    simconnect = null;
                }
            }
            catch (Exception ex)
            {
                logger.LogWarning(ex, $"Cannot unsubscribe events! Error: {ex.Message}");
            }
        }
Example #3
0
        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}");
            }
        }