File tree Expand file tree Collapse file tree 1 file changed +21
-5
lines changed
src/WorkflowCore/Services/BackgroundTasks Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,12 @@ private async void Execute()
61
61
{
62
62
try
63
63
{
64
- if ( activeTasks . Count >= MaxConcurrentItems )
64
+ var activeCount = 0 ;
65
+ lock ( activeTasks )
66
+ {
67
+ activeCount = activeTasks . Count ;
68
+ }
69
+ if ( activeCount >= MaxConcurrentItems )
65
70
{
66
71
await Task . Delay ( Options . IdleTime ) ;
67
72
continue ;
@@ -75,14 +80,19 @@ private async void Execute()
75
80
await Task . Delay ( Options . IdleTime , cancelToken ) ;
76
81
continue ;
77
82
}
78
-
79
- if ( activeTasks . ContainsKey ( item ) )
83
+
84
+ var hasTask = false ;
85
+ lock ( activeTasks )
86
+ {
87
+ hasTask = activeTasks . ContainsKey ( item ) ;
88
+ }
89
+ if ( hasTask )
80
90
{
81
91
secondPasses . Add ( item ) ;
82
92
if ( ! EnableSecondPasses )
83
93
await QueueProvider . QueueWork ( item , Queue ) ;
84
94
continue ;
85
- }
95
+ }
86
96
87
97
secondPasses . TryRemove ( item ) ;
88
98
@@ -121,7 +131,13 @@ private async void Execute()
121
131
}
122
132
}
123
133
124
- foreach ( var task in activeTasks . Values )
134
+ List < Task > toComplete ;
135
+ lock ( activeTasks )
136
+ {
137
+ toComplete = activeTasks . Values . ToList ( ) ;
138
+ }
139
+
140
+ foreach ( var task in toComplete )
125
141
task . Wait ( ) ;
126
142
}
127
143
You can’t perform that action at this time.
0 commit comments