Skip to content

Commit 0b0a185

Browse files
authored
Merge pull request #407 from Flow-Launcher/fixConcurrentAccessIssue
Fix concurrent access issue
2 parents 888b44f + bad5504 commit 0b0a185

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Flow.Launcher.Core/Plugin/PluginAssemblyLoader.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Flow.Launcher.Infrastructure;
22
using System;
3+
using System.Collections.Concurrent;
34
using System.Collections.Generic;
45
using System.IO;
56
using System.Linq;
@@ -14,14 +15,17 @@ internal class PluginAssemblyLoader : AssemblyLoadContext
1415

1516
private readonly AssemblyName assemblyName;
1617

17-
private static readonly List<Assembly> loadedAssembly;
18+
private static readonly ConcurrentDictionary<string, byte> loadedAssembly;
1819

1920
static PluginAssemblyLoader()
2021
{
21-
loadedAssembly = new List<Assembly>(AppDomain.CurrentDomain.GetAssemblies());
22+
var currentAssemblies = AppDomain.CurrentDomain.GetAssemblies();
23+
loadedAssembly = new ConcurrentDictionary<string, byte>(
24+
currentAssemblies.Select(x => new KeyValuePair<string, byte>(x.FullName, default)));
25+
2226
AppDomain.CurrentDomain.AssemblyLoad += (sender, args) =>
2327
{
24-
loadedAssembly.Add(args.LoadedAssembly);
28+
loadedAssembly[args.LoadedAssembly.FullName] = default;
2529
};
2630
}
2731

@@ -57,9 +61,7 @@ internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, Type type)
5761

5862
internal bool ExistsInReferencedPackage(AssemblyName assemblyName)
5963
{
60-
if (loadedAssembly.Any(a => a.FullName == assemblyName.FullName))
61-
return true;
62-
return false;
64+
return loadedAssembly.ContainsKey(assemblyName.FullName);
6365
}
6466
}
6567
}

0 commit comments

Comments
 (0)