diff --git a/ColorControl/ColorControl.csproj b/ColorControl/ColorControl.csproj
index 9c1557b..2e1c2c5 100644
--- a/ColorControl/ColorControl.csproj
+++ b/ColorControl/ColorControl.csproj
@@ -27,7 +27,7 @@
ColorControl
Maassoft
0
- 1.3.1.0
+ 1.3.2.0
false
true
true
diff --git a/ColorControl/LgService.cs b/ColorControl/LgService.cs
index a746abe..15360b5 100644
--- a/ColorControl/LgService.cs
+++ b/ColorControl/LgService.cs
@@ -86,30 +86,26 @@ namespace ColorControl
File.WriteAllText(_configFilename, json);
}
- public void RefreshDevices(Action callBack = null)
+ public async Task RefreshDevices(bool connect = true)
{
- Utils.GetPnpDevices(LgDeviceSearchKey).ContinueWith((task) =>
+ var devices = await Utils.GetPnpDevices(LgDeviceSearchKey);
+ SetDevices(devices);
+ if (connect && SelectedDevice != null)
{
- SetDevicesTask(task);
- callBack?.Invoke();
- if (callBack == null && SelectedDevice != null)
+ if (Config.PowerOnAfterStartup && _allowPowerOn)
{
- if (Config.PowerOnAfterStartup && _allowPowerOn)
- {
- WakeAndConnectToSelectedDevice(0);
- }
- else
- {
- ConnectToSelectedDevice();
- }
+ WakeAndConnectToSelectedDevice(0);
+ }
+ else
+ {
+ ConnectToSelectedDevice();
}
}
- );
}
- private void SetDevicesTask(Task> task)
+ private void SetDevices(List devices)
{
- Devices = task.Result;
+ Devices = devices;
if (Devices?.Count > 0)
{
var preferredDevice = Devices.FirstOrDefault(x => x.MacAddress != null && x.MacAddress.Equals(Config.PreferredMacAddress)) ?? Devices[0];
diff --git a/ColorControl/MainForm.cs b/ColorControl/MainForm.cs
index 41762ae..bb95b5e 100644
--- a/ColorControl/MainForm.cs
+++ b/ColorControl/MainForm.cs
@@ -1419,7 +1419,7 @@ namespace ColorControl
var devices = _lgService.Devices;
if (devices == null || !devices.Any())
{
- _lgService.RefreshDevices(() => BeginInvoke(new Action(FillLgDevices)));
+ _lgService.RefreshDevices(false).ContinueWith((task) => BeginInvoke(new Action(FillLgDevices)));
}
else
{
diff --git a/ColorControl/NvService.cs b/ColorControl/NvService.cs
index 017d7aa..ce70a09 100644
--- a/ColorControl/NvService.cs
+++ b/ColorControl/NvService.cs
@@ -38,6 +38,7 @@ namespace ColorControl
};
private Display _currentDisplay;
+ private bool _initialized = false;
public NvService()
{
@@ -193,11 +194,15 @@ namespace ColorControl
protected override void Initialize()
{
NVIDIA.Initialize();
+ _initialized = true;
}
protected override void Uninitialize()
{
- NVIDIA.Unload();
+ if (_initialized)
+ {
+ NVIDIA.Unload();
+ }
}
}
}
diff --git a/ColorControl/Program.cs b/ColorControl/Program.cs
index a31b045..3add68a 100644
--- a/ColorControl/Program.cs
+++ b/ColorControl/Program.cs
@@ -12,6 +12,12 @@ namespace ColorControl
[STAThread]
static void Main(string[] args)
{
+ var currentDomain = AppDomain.CurrentDomain;
+ // Handler for unhandled exceptions.
+ currentDomain.UnhandledException += GlobalUnhandledExceptionHandler;
+ // Handler for exceptions in threads behind forms.
+ Application.ThreadException += GlobalThreadExceptionHandler;
+
var startUpParams = StartUpParams.Parse(args);
if (startUpParams.ActivateChromeFontFix || startUpParams.DeactivateChromeFontFix)
@@ -51,5 +57,17 @@ namespace ColorControl
}
}
}
+
+ private static void GlobalUnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
+ {
+ var ex = (Exception)e.ExceptionObject;
+ MessageBox.Show("Unhandled exception: " + ex.ToLogString(Environment.StackTrace), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ private static void GlobalThreadExceptionHandler(object sender, System.Threading.ThreadExceptionEventArgs e)
+ {
+ var ex = e.Exception;
+ MessageBox.Show("Exception in thread: " + ex.ToLogString(Environment.StackTrace), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
}
}
diff --git a/ColorControl/Properties/AssemblyInfo.cs b/ColorControl/Properties/AssemblyInfo.cs
index ede13d2..8faa96b 100644
--- a/ColorControl/Properties/AssemblyInfo.cs
+++ b/ColorControl/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.3.1.0")]
-[assembly: AssemblyFileVersion("1.3.1.0")]
+[assembly: AssemblyVersion("1.3.2.0")]
+[assembly: AssemblyFileVersion("1.3.2.0")]