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
The VSTHRD003 is triggered when using a combination of Task.Run and Task.WhenAny in a "top-level statements" (programs without Main methods) console app
Repro steps
This "top-level statements" code will trigger VSTHRD003
usingvarcts=newCancellationTokenSource();varloopTask=Task.Run(async()=>{// DO SOMETHING...},cts.Token);varserverTask=Task.Run(async()=>{// DO SOMETHING...},cts.Token);varexitTask=Task.Run(()=>{Console.WriteLine("Press any key to exit");Console.ReadKey();cts.Cancel();},cts.Token);awaitTask.WhenAny(loopTask,serverTask,exitTask);/// VSTHRD003 is triggered here !Console.WriteLine("Exited");
This traditional console app, on the other hand, does not trigger VSTHRD003
publicstaticclassProgram{publicstaticasyncTaskMain(string[]args){usingvarcts=newCancellationTokenSource();varloopTask=Task.Run(async()=>{// DO SOMETHING...},cts.Token);varserverTask=Task.Run(async()=>{// DO SOMETHING...},cts.Token);varexitTask=Task.Run(()=>{Console.WriteLine("Press any key to exit");Console.ReadKey();cts.Cancel();},cts.Token);awaitTask.WhenAny(loopTask,serverTask,exitTask);/// VSTHRD003 is NOT triggered here !Console.WriteLine("Exited");}}
Expected behavior
VSTHRD003 should not be triggered in this scenario
Actual behavior
VSTHRD003 is triggered in this scenario, and it shouldn't
Version used: 17.12.19.10947
The text was updated successfully, but these errors were encountered:
Bug description
The VSTHRD003 is triggered when using a combination of
Task.Run
andTask.WhenAny
in a "top-level statements" (programs without Main methods) console appRepro steps
This "top-level statements" code will trigger VSTHRD003
This traditional console app, on the other hand, does not trigger VSTHRD003
Expected behavior
VSTHRD003 should not be triggered in this scenario
Actual behavior
VSTHRD003 is triggered in this scenario, and it shouldn't
The text was updated successfully, but these errors were encountered: