mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-10-03 10:36:30 +13:00
Fix data access of UI thread's data while file system watcher is executing
This commit is contained in:
parent
562a799a46
commit
176e9f896d
2 changed files with 21 additions and 4 deletions
|
@ -1219,7 +1219,17 @@ namespace SystemTrayMenu.Business
|
||||||
|
|
||||||
private void WatcherProcessItem(object sender, EventArgs e)
|
private void WatcherProcessItem(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (menus[0] == null || !menus[0].IsLoaded)
|
bool UseHistory = false;
|
||||||
|
if (menus[0] == null)
|
||||||
|
{
|
||||||
|
UseHistory = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
menus[0].Dispatcher.Invoke(() => UseHistory = !menus[0].IsLoaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (UseHistory)
|
||||||
{
|
{
|
||||||
watcherHistory.Add(e);
|
watcherHistory.Add(e);
|
||||||
return;
|
return;
|
||||||
|
@ -1305,7 +1315,7 @@ namespace SystemTrayMenu.Business
|
||||||
{
|
{
|
||||||
List<ListViewItemData> rowsToRemove = new();
|
List<ListViewItemData> rowsToRemove = new();
|
||||||
|
|
||||||
foreach (ListViewItemData item in dgv.Items)
|
foreach (ListViewItemData item in dgv.ItemsSource)
|
||||||
{
|
{
|
||||||
RowData rowData = item.data;
|
RowData rowData = item.data;
|
||||||
if (rowData.Path == e.FullPath ||
|
if (rowData.Path == e.FullPath ||
|
||||||
|
@ -1318,7 +1328,7 @@ namespace SystemTrayMenu.Business
|
||||||
|
|
||||||
foreach (ListViewItemData rowToRemove in rowsToRemove)
|
foreach (ListViewItemData rowToRemove in rowsToRemove)
|
||||||
{
|
{
|
||||||
dgv.Items.Remove(rowToRemove);
|
((IEditableCollectionView)dgv.Items).Remove(rowToRemove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,14 @@ namespace SystemTrayMenu.Business
|
||||||
GetNetworkRootDirectories(path, ref menuData);
|
GetNetworkRootDirectories(path, ref menuData);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (!Directory.Exists(path))
|
||||||
|
{
|
||||||
|
// Happens most likely when a shortcut is pointing to an absent target path
|
||||||
|
Log.Info($"path:'{path}' does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
GetDirectories(worker, path, ref menuData);
|
GetDirectories(worker, path, ref menuData);
|
||||||
GetFiles(worker, path, ref menuData);
|
GetFiles(worker, path, ref menuData);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue