File tree Expand file tree Collapse file tree 1 file changed +25
-14
lines changed Expand file tree Collapse file tree 1 file changed +25
-14
lines changed Original file line number Diff line number Diff line change @@ -53,24 +53,35 @@ public DrivesManager()
53
53
54
54
private async void DeviceWatcher_EnumerationCompleted ( DeviceWatcher sender , object args )
55
55
{
56
- if ( App . sideBarItems . FirstOrDefault ( x => x is HeaderTextItem && x . Text == "Drives" ) == null )
57
- {
58
- App . sideBarItems . Add ( new HeaderTextItem ( ) { Text = "Drives" } ) ;
59
- }
60
- foreach ( DriveItem drive in Drives )
56
+ // Only update collection from UI-thread
57
+ try
61
58
{
62
- if ( ! App . sideBarItems . Contains ( drive ) )
59
+ await CoreApplication . MainView . Dispatcher . RunAsync ( CoreDispatcherPriority . Low , ( ) =>
63
60
{
64
- App . sideBarItems . Add ( drive ) ;
65
- }
66
- }
61
+ if ( App . sideBarItems . FirstOrDefault ( x => x is HeaderTextItem && x . Text == "Drives" ) == null )
62
+ {
63
+ App . sideBarItems . Add ( new HeaderTextItem ( ) { Text = "Drives" } ) ;
64
+ }
65
+ foreach ( DriveItem drive in Drives )
66
+ {
67
+ if ( ! App . sideBarItems . Contains ( drive ) )
68
+ {
69
+ App . sideBarItems . Add ( drive ) ;
70
+ }
71
+ }
67
72
68
- foreach ( INavigationControlItem item in App . sideBarItems . ToList ( ) )
73
+ foreach ( INavigationControlItem item in App . sideBarItems . ToList ( ) )
74
+ {
75
+ if ( item is DriveItem && ! Drives . Contains ( item ) )
76
+ {
77
+ App . sideBarItems . Remove ( item ) ;
78
+ }
79
+ }
80
+ } ) ;
81
+ }
82
+ catch ( Exception )
69
83
{
70
- if ( item is DriveItem && ! Drives . Contains ( item ) )
71
- {
72
- App . sideBarItems . Remove ( item ) ;
73
- }
84
+ // UI thread not created yet?
74
85
}
75
86
}
76
87
You can’t perform that action at this time.
0 commit comments