Skip to content

Commit

Permalink
Merge pull request #4004 from EraserKing/3961-check-is-single-threade…
Browse files Browse the repository at this point in the history
…d-again

Force the OneTimeTearDown to be executed on the current thread if STA
  • Loading branch information
OsirisTerje committed Apr 5, 2023
2 parents 99a2ede + f08de65 commit 0b75bff
Showing 1 changed file with 25 additions and 17 deletions.
Expand Up @@ -192,24 +192,32 @@ private void Dispatch(WorkItem work, ParallelExecutionStrategy strategy)
}
}

switch (strategy)
// The attribute SingleThreaded may not be applied to the content in time, so here as a workaround, check for the flag again
if (work.Context.IsSingleThreaded)
{
default:
case ParallelExecutionStrategy.Direct:
work.Execute();
break;
case ParallelExecutionStrategy.Parallel:
if (work.TargetApartment == ApartmentState.STA)
ParallelSTAQueue.Enqueue(work);
else
ParallelQueue.Enqueue(work);
break;
case ParallelExecutionStrategy.NonParallel:
if (work.TargetApartment == ApartmentState.STA)
NonParallelSTAQueue.Enqueue(work);
else
NonParallelQueue.Enqueue(work);
break;
work.Execute();
}
else
{
switch (strategy)
{
default:
case ParallelExecutionStrategy.Direct:
work.Execute();
break;
case ParallelExecutionStrategy.Parallel:
if (work.TargetApartment == ApartmentState.STA)
ParallelSTAQueue.Enqueue(work);
else
ParallelQueue.Enqueue(work);
break;
case ParallelExecutionStrategy.NonParallel:
if (work.TargetApartment == ApartmentState.STA)
NonParallelSTAQueue.Enqueue(work);
else
NonParallelQueue.Enqueue(work);
break;
}
}
}

Expand Down

0 comments on commit 0b75bff

Please sign in to comment.