Skip to content

Commit 31f1c4e

Browse files
committed
Fix: Dispatcher called before created
1 parent f2391ee commit 31f1c4e

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

Files/App.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,24 @@ public App()
6767
Clipboard_ContentChanged(null, null);
6868
AppCenter.Start("682666d1-51d3-4e4a-93d0-d028d43baaa0", typeof(Analytics), typeof(Crashes));
6969

70+
/*
7071
AppSettings = new SettingsViewModel();
7172
7273
SetPropertiesFromLocalSettings();
7374
7475
PopulatePinnedSidebarItems();
7576
DetectWSLDistros();
77+
*/
78+
79+
Init();
80+
}
81+
82+
private void Init()
83+
{
84+
AppSettings = new SettingsViewModel();
85+
SetPropertiesFromLocalSettings();
86+
PopulatePinnedSidebarItems();
87+
DetectWSLDistros();
7688
}
7789

7890
public void CloseOpenPopups()

Files/Filesystem/Drives.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args)
6767
Visibility.Visible,
6868
type);
6969

70-
CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Drives.Add(driveItem); });
70+
// Update the collection on the ui-thread.
71+
try
72+
{
73+
CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Drives.Add(driveItem); });
74+
}
75+
catch (Exception e)
76+
{
77+
// Ui-Thread not yet created.
78+
Drives.Add(driveItem);
79+
}
7180
}
7281

7382
private async void DeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate args)
@@ -81,8 +90,16 @@ private async void DeviceRemoved(DeviceWatcher sender, DeviceInformationUpdate a
8190
continue;
8291
}
8392

84-
await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low,
85-
() => { Drives.Remove(drive); });
93+
// Update the collection on the ui-thread.
94+
try
95+
{
96+
CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Drives.Remove(drive); });
97+
}
98+
catch (Exception e)
99+
{
100+
// Ui-Thread not yet created.
101+
Drives.Remove(drive);
102+
}
86103
return;
87104
}
88105
}

Files/Settings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ namespace Files
99
public static class LocalSettings
1010
{
1111
public const string DateTimeFormat = "datetimeformat";
12+
public const string Theme = "theme";
1213
}
1314
}

0 commit comments

Comments
 (0)