mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-06 03:07:54 +08:00
Fix errors that collections has been changed while foreach collections
This commit is contained in:
parent
3c4a9a05a0
commit
5855ff0d27
@ -7,6 +7,7 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
||||
internal class MFTSearcherCache
|
||||
{
|
||||
public Dictionary<string, Dictionary<ulong, USNRecord>> VolumeRecords = new Dictionary<string, Dictionary<ulong, USNRecord>>();
|
||||
public static object locker = new object();
|
||||
|
||||
public MFTSearcherCache() { }
|
||||
|
||||
@ -25,10 +26,13 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
||||
{
|
||||
EnsureVolumeExistInHashTable(volume);
|
||||
if (!VolumeRecords[volume].ContainsKey(record.FRN))
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
VolumeRecords[volume].Add(record.FRN, record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void EnsureVolumeExistInHashTable(string volume)
|
||||
{
|
||||
@ -46,8 +50,11 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
||||
private bool DeleteRecordHashTableItem(Dictionary<string, Dictionary<ulong, USNRecord>> hashtable, string volume, ulong frn)
|
||||
{
|
||||
if (hashtable.ContainsKey(volume) && hashtable[volume].ContainsKey(frn))
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
hashtable[volume].Remove(frn);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -64,8 +71,11 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
||||
private bool RealUpdateRecord(string volume, Dictionary<string, Dictionary<ulong, USNRecord>> source, USNRecord record)
|
||||
{
|
||||
if (source.ContainsKey(volume) && source[volume].ContainsKey(record.FRN))
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
source[volume][record.FRN] = record;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -77,7 +87,8 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
||||
public List<USNRecord> FindByName(string filename, long maxResult = -1)
|
||||
{
|
||||
List<USNRecord> result = new List<USNRecord>();
|
||||
|
||||
lock (locker)
|
||||
{
|
||||
foreach (Dictionary<ulong, USNRecord> dictionary in VolumeRecords.Values)
|
||||
{
|
||||
foreach (var usnRecord in dictionary)
|
||||
@ -90,7 +101,7 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
||||
if (maxResult > 0 && result.Count() >= maxResult) break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user