Skip to content

Commit be07bbf

Browse files
authored
Merge pull request #8734 from dotnet/merge/release/9.0.2xx-to-release/9.0.3xx
[automated] Merge branch 'release/9.0.2xx' => 'release/9.0.3xx'
2 parents a8fd123 + d0e0b2c commit be07bbf

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Microsoft.TemplateEngine.Edge/Constraints/WorkloadConstraintFactory.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace Microsoft.TemplateEngine.Edge.Constraints
1111
{
1212
public sealed class WorkloadConstraintFactory : ITemplateConstraintFactory
1313
{
14+
private static readonly SemaphoreSlim Mutex = new(1);
15+
1416
Guid IIdentifiedComponent.Id { get; } = Guid.Parse("{F8BA5B13-7BD6-47C8-838C-66626526817B}");
1517

1618
string ITemplateConstraintFactory.Type => "workload";
@@ -97,8 +99,17 @@ private static IEnumerable<string> ParseArgs(string? args)
9799
}
98100

99101
token.ThrowIfCancellationRequested();
100-
IEnumerable<WorkloadInfo> currentProviderWorkloads = await providers[0].GetInstalledWorkloadsAsync(token).ConfigureAwait(false);
101-
workloads = currentProviderWorkloads.ToList();
102+
103+
await Mutex.WaitAsync(token).ConfigureAwait(false);
104+
try
105+
{
106+
IEnumerable<WorkloadInfo> currentProviderWorkloads = await providers[0].GetInstalledWorkloadsAsync(token).ConfigureAwait(false);
107+
workloads = currentProviderWorkloads.ToList();
108+
}
109+
finally
110+
{
111+
Mutex.Release();
112+
}
102113

103114
if (workloads.Select(w => w.Id).HasDuplicates(StringComparer.InvariantCultureIgnoreCase))
104115
{

0 commit comments

Comments
 (0)