Better disconnect handling

This commit is contained in:
IceStormNG
2023-07-23 10:53:30 +02:00
parent 86c960e01b
commit 7dfe830dac

View File

@@ -143,6 +143,12 @@ namespace GHelper.Peripherals.Mouse
HidSharp.DeviceList.Local.Changed += Device_Changed;
}
public override void Dispose()
{
HidSharp.DeviceList.Local.Changed -= Device_Changed;
base.Dispose();
}
private void Device_Changed(object? sender, HidSharp.DeviceListChangedEventArgs e)
{
//Use this to validate whether the device is still connected.
@@ -201,6 +207,12 @@ namespace GHelper.Peripherals.Mouse
Logger.WriteLine(GetDisplayName() + ": Timeout reading packet " + e.Message);
return null;
}
catch (System.ObjectDisposedException e)
{
Logger.WriteLine(GetDisplayName() + ": Channel closed ");
OnDisconnect();
return null;
}
return response;
@@ -655,7 +667,6 @@ namespace GHelper.Peripherals.Mouse
for (int i = 0; i < DPIProfileCount(); ++i)
{
Logger.WriteLine(GetDisplayName() + ": Read DPI Setting " + (i + 1) + ": " + DpiSettings[i].ToString());
}