-
We have a console project in .NET 8 and we have recently attempted to upgrade vs-threading library. As a result, many VSTHRD003 warnings appeared. My understanding of rule 3 is that it is a general rule that has proven good for big projects such as Visual Studio. However, in some sense the rule is arbitrary and one can program even with Is my understanding correct or is there a different idea behind it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
VSTHRD003 helps any application with a main thread avoid deadlocks if you ever have the need to synchronously block the main thread while waiting for async work to complete. It doesn't have to be a big application to matter. I can create a brand new WPF/WinForms app and demonstrate the hang that VSTHRD003 helps to avoid in perhaps 5 lines of code. But if you have no main thread in your app (or if a library, if no application that uses your library will ever have a main thread), and/or if the application(s) will never block the main thread on async work that might need the main thread to complete their work, then ya, you can disable this rule. And as the 'fix' for this often is to use JoinableTaskFactory, if you don't use JTF and have no intention of doing so, then by all means disable the rule. |
Beta Was this translation helpful? Give feedback.
VSTHRD003 helps any application with a main thread avoid deadlocks if you ever have the need to synchronously block the main thread while waiting for async work to complete. It doesn't have to be a big application to matter. I can create a brand new WPF/WinForms app and demonstrate the hang that VSTHRD003 helps to avoid in perhaps 5 lines of code.
But if you have no main thread in your app (or if a library, if no application that uses your library will ever have a main thread), and/or if the application(s) will never block the main thread on async work that might need the main thread to complete their work, then ya, you can disable this rule.
And as the 'fix' for this often is to use Join…