mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-07 20:07:56 +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
|
internal class MFTSearcherCache
|
||||||
{
|
{
|
||||||
public Dictionary<string, Dictionary<ulong, USNRecord>> VolumeRecords = new Dictionary<string, Dictionary<ulong, USNRecord>>();
|
public Dictionary<string, Dictionary<ulong, USNRecord>> VolumeRecords = new Dictionary<string, Dictionary<ulong, USNRecord>>();
|
||||||
|
public static object locker = new object();
|
||||||
|
|
||||||
public MFTSearcherCache() { }
|
public MFTSearcherCache() { }
|
||||||
|
|
||||||
@ -25,10 +26,13 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
|||||||
{
|
{
|
||||||
EnsureVolumeExistInHashTable(volume);
|
EnsureVolumeExistInHashTable(volume);
|
||||||
if (!VolumeRecords[volume].ContainsKey(record.FRN))
|
if (!VolumeRecords[volume].ContainsKey(record.FRN))
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
{
|
{
|
||||||
VolumeRecords[volume].Add(record.FRN, record);
|
VolumeRecords[volume].Add(record.FRN, record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void EnsureVolumeExistInHashTable(string volume)
|
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)
|
private bool DeleteRecordHashTableItem(Dictionary<string, Dictionary<ulong, USNRecord>> hashtable, string volume, ulong frn)
|
||||||
{
|
{
|
||||||
if (hashtable.ContainsKey(volume) && hashtable[volume].ContainsKey(frn))
|
if (hashtable.ContainsKey(volume) && hashtable[volume].ContainsKey(frn))
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
{
|
{
|
||||||
hashtable[volume].Remove(frn);
|
hashtable[volume].Remove(frn);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -64,8 +71,11 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
|||||||
private bool RealUpdateRecord(string volume, Dictionary<string, Dictionary<ulong, USNRecord>> source, USNRecord record)
|
private bool RealUpdateRecord(string volume, Dictionary<string, Dictionary<ulong, USNRecord>> source, USNRecord record)
|
||||||
{
|
{
|
||||||
if (source.ContainsKey(volume) && source[volume].ContainsKey(record.FRN))
|
if (source.ContainsKey(volume) && source[volume].ContainsKey(record.FRN))
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
{
|
{
|
||||||
source[volume][record.FRN] = record;
|
source[volume][record.FRN] = record;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -77,7 +87,8 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
|||||||
public List<USNRecord> FindByName(string filename, long maxResult = -1)
|
public List<USNRecord> FindByName(string filename, long maxResult = -1)
|
||||||
{
|
{
|
||||||
List<USNRecord> result = new List<USNRecord>();
|
List<USNRecord> result = new List<USNRecord>();
|
||||||
|
lock (locker)
|
||||||
|
{
|
||||||
foreach (Dictionary<ulong, USNRecord> dictionary in VolumeRecords.Values)
|
foreach (Dictionary<ulong, USNRecord> dictionary in VolumeRecords.Values)
|
||||||
{
|
{
|
||||||
foreach (var usnRecord in dictionary)
|
foreach (var usnRecord in dictionary)
|
||||||
@ -90,7 +101,7 @@ namespace Wox.Plugin.FindFile.MFTSearch
|
|||||||
if (maxResult > 0 && result.Count() >= maxResult) break;
|
if (maxResult > 0 && result.Count() >= maxResult) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user