You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change #1321 replaced Task.Run with a call to Task.Factory.StartNew with some TaskCreationOptions, but it didn't specify the TaskScheduler, which actually changed the behavior from using TaskScheduler.Default to TaskScheduler.Current
The very confusingly named TaskScheduler.Default is not the default when calling Task.Factory.StartNew, TaskScheduler.Current is the default. To preserve existing behavior the line should be updated to _mainLoopTask = Task.Factory.StartNew(MainLoop, CancellationToken.None, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
Describe the bug
This change #1321 replaced Task.Run with a call to Task.Factory.StartNew with some TaskCreationOptions, but it didn't specify the TaskScheduler, which actually changed the behavior from using TaskScheduler.Default to TaskScheduler.Current
https://devblogs.microsoft.com/pfxteam/task-run-vs-task-factory-startnew/
The very confusingly named TaskScheduler.Default is not the default when calling Task.Factory.StartNew, TaskScheduler.Current is the default. To preserve existing behavior the line should be updated to
_mainLoopTask = Task.Factory.StartNew(MainLoop, CancellationToken.None, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
The change in 6.5.0 caused my UI application to freeze on startup after some code to connect to rabbitmq in a background task called into rabbitmq code, the scenario is best described here in this 11 year old question predicting this issue being frequent due to the design of the task api:
https://stackoverflow.com/questions/6800705/why-is-taskscheduler-current-the-default-taskscheduler
Reproduction steps
From UI thread, use Task.Factory.StartNew(action) to run code that then initiates a rabbitmq connection. This works in 6.4 but freezes in 6.5
Expected behavior
MainLoop should always run on TaskScheduler.Default
Additional context
No response
The text was updated successfully, but these errors were encountered: