ContinueWith or TaskFactory.StartNew runs on whatever scheduler is current, as no scheduler is passed
What it finds
Without an explicit TaskScheduler, ContinueWith and Task.Factory.StartNew use TaskScheduler.Current, the scheduler of the task that happens to be running. Called from a UI continuation, work meant for the thread pool then runs on the UI thread. Passing TaskScheduler.Default, or using Task.Run and await, makes the choice explicit.
From the rule's source, task_without_scheduler.rs.
using System.Threading.Tasks; class Jobs{ void Run(Task task) { task.ContinueWith(t => Log());tx0 reports: ContinueWith runs on the current scheduler, which depends on the caller task.ContinueWith(t => Log(), TaskScheduler.Default); Task.Factory.StartNew(Log);tx0 reports: StartNew runs on the current scheduler, which depends on the caller } void Log() { }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:task-without-scheduler" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:task-without-scheduler] reason="..."tx0 explain tx0/csharp:task-without-scheduler shows the same in the terminal. Found a false positive? Report it.