File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
test/Microsoft.VisualStudio.Threading.Tests Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -4179,6 +4179,7 @@ private async Task<JoinableTask> SpinOffMainThreadTaskForJoinableTaskDependencie
41794179
41804180 using ( this . context . SuppressRelevance ( ) )
41814181 {
4182+ // this task creates a circular loop.
41824183 task2 = joinableTaskFactory . RunAsync ( async ( ) =>
41834184 {
41844185 joinableTaskCollection . Join ( ) ;
@@ -4221,12 +4222,18 @@ private async Task<JoinableTask> SpinOffMainThreadTaskForJoinableTaskDependencie
42214222
42224223 await this . context . Factory . SwitchToMainThreadAsync ( ) ;
42234224
4225+ // Due to circular reference, this add/remove reference to lead incompleted state
4226+ // the joinableTaskCollection will retain refcount to the JTF.Run task.
42244227 using ( joinableTaskCollection . Join ( ) )
42254228 {
42264229 }
42274230
42284231 using ( mainThreadJoinedCollection . Join ( ) )
42294232 {
4233+ // This IsMainThreadBlocked triggers the incompleted state to be cleaned up.
4234+ // JTF.Run joins the completed task through the middle collection to expose the
4235+ // inconsistent between two logic, so the recomputation won't clean up the circular
4236+ // dependency loop correctly.
42304237 await this . context . Factory . RunAsync ( ( ) =>
42314238 {
42324239 return Task . FromResult ( this . context . IsMainThreadBlocked ( ) ) ;
You can’t perform that action at this time.
0 commit comments