Skip to content

Commit

Permalink
Change Aircraft Label thread safe (#1341)
Browse files Browse the repository at this point in the history
* Change Aircraft Label thread safe
* Removing unnecessary using statements
  • Loading branch information
DocMoebiuz authored Oct 24, 2023
1 parent 825662d commit 1325c89
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions UI/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Resources;
using System.Windows.Forms;
using System.Diagnostics;
using System.Xml.Serialization;
#if ARCAZE
using SimpleSolutions.Usb;
#endif
using System.Runtime.InteropServices;
using MobiFlight.FSUIPC;
Expand All @@ -20,18 +15,18 @@
using MobiFlight.SimConnectMSFS;
using MobiFlight.UpdateChecker;
using MobiFlight.Base;
using Microsoft.ApplicationInsights.DataContracts;
using MobiFlight.xplane;
using MobiFlight.HubHop;
using System.Threading.Tasks;
using MobiFlight.InputConfig;
using FSUIPC;
using Newtonsoft.Json;

namespace MobiFlight.UI
{
public partial class MainForm : Form
{
delegate void UpdateAircraftCallback(string aircraftName);

public static String Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(3);
public static String VersionBeta = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(4);
public static String Build = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).LastWriteTime.ToString("yyyyMMdd");
Expand Down Expand Up @@ -252,14 +247,25 @@ private void MainForm_Shown(object sender, EventArgs e)
moduleToolStripDropDownButton.ToolTipText = i18n._tr("uiMessageNoModuleFound");
}

private void ExecManager_OnSimAircraftChanged(object sender, string e)
private void ExecManager_OnSimAircraftChanged(object sender, string aircraftName)
{
var aircraftName = e;
if (this.InvokeRequired)
{
this.Invoke(new UpdateAircraftCallback(UpdateAircraft), new object[] { aircraftName });
}
else
{
UpdateAircraft(aircraftName);
}
}

private void UpdateAircraft(String aircraftName)
{
if (aircraftName == "")
{
aircraftName = i18n._tr("uiLabelNoAircraftDetected.");
}

toolStripAircraftDropDownButton.Text = aircraftName;
toolStripAircraftDropDownButton.DropDown.Enabled = true;

Expand All @@ -271,7 +277,9 @@ private void ExecManager_OnSimAircraftChanged(object sender, string e)

var filename = AutoLoadConfigs[key];

Log.Instance.log($"Auto loading config for {e}", LogSeverity.Info);
if (currentFileName == filename) return;

Log.Instance.log($"Auto loading config for {aircraftName}", LogSeverity.Info);
LoadConfig(filename);
}

Expand Down

0 comments on commit 1325c89

Please sign in to comment.