Skip to content

Commit c97f49b

Browse files
committed
Better handling of radio to avoid crashes on some systems resolves #42
1 parent c262084 commit c97f49b

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

XBatteryStatus/MyApplicationContext.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,7 @@ public MyApplicationContext()
105105

106106
notifyIcon.ContextMenuStrip = contextMenu;
107107

108-
var radios = Radio.GetRadiosAsync().GetResults();
109-
bluetoothRadio = radios.FirstOrDefault(radio => radio.Kind == RadioKind.Bluetooth);
110-
if (bluetoothRadio != null)
111-
{
112-
bluetoothRadio.StateChanged += BluetoothRadio_StateChanged;
113-
}
114-
115-
108+
InitializeBluetoothRadioAsync();
116109
FindBleController();
117110

118111
UpdateTimer = new Timer();
@@ -126,6 +119,23 @@ public MyApplicationContext()
126119
DiscoverTimer.Start();
127120
}
128121

122+
private async void InitializeBluetoothRadioAsync()
123+
{
124+
try
125+
{
126+
var radios = await Radio.GetRadiosAsync();
127+
bluetoothRadio = radios.FirstOrDefault(radio => radio.Kind == RadioKind.Bluetooth);
128+
if (bluetoothRadio != null)
129+
{
130+
bluetoothRadio.StateChanged += BluetoothRadio_StateChanged;
131+
}
132+
}
133+
catch (Exception e)
134+
{
135+
LogError(e);
136+
}
137+
}
138+
129139
private void CheckSoftwareUpdate()
130140
{
131141
try

0 commit comments

Comments
 (0)