- VS 2022 (Version 17.2.5) or higher
For previous VS 2019 support, see the separate Parallel Checker release on VS Marketplace:
The Parallel Checker is an extension that detects data races, deadlocks and other concurrency issues in C#.
- The checker will automatically enable C# full solution analysis.
To disable this, go to Tools->Options->Parallel Checker, then set "Automatic full solution analysis" to "false". Subsequently, navigate to the option "Text Editor->C#->Advanced->Run background code analysis for:" and select another value than "Entire solution". Restart VS.
- Checker information messages (with the blue icon) are turned on by default. To deactivate them, go to "Tools->Options->Parallel Checker": Set "Diagnostic Checker Information" to "false". Reload the solution or restart VS.
- If checker messages are not being displayed, please activate “entire solution analysis” manually: Go to menu “Tools->Options”, navigate to “Text Editor->C#->Advanced”, and select “Entire solution” under “Run background code analysis for:”.
- If messages do not appear right away after opening the solution, it may help to edit the source code a little bit to trigger the background analysis process in VS.
- In VS, open Tools->Extensions and Update, search online for “Parallel Checker” and download “Parallel Checker for C# 9 (VS 2022)”.
- Restart VS, the VSIX installer will appear, click “Install”, and the tool will be installed. It can be installed for a single or multiple IDE-instances.
- Open VS studio and open a solution with an empty C# console application project.
- To test the installation, paste the following code into “Program.cs” that contains a data race:
static void Main()
int x = 0;
Task.Run(() => x++);
- Open the “Error List” view. Concurrency errors detected by the parallel checker will here be listed after some delay of a few seconds.
- If checker messages are not being displayed right away, edit the code a little bit, to trigger the background analysis process in VS. Or alternatively, you may build the solution.
- Issues are also underlined in the code.
Hint: If checker messages are still not being displayed, you need to activate full solution analysis manually: Go to menu "Tools->Options", navigate to "Text Editor->C#->Advanced", and select "Entire solution" under "Run background code analysis for:":
The checker detects the following concurrency (multi-threading) issues with a static analysis, however, not necessarily all of them:
- Data Races: Unsynchronized concurrent accesses to same variable or array element, involving at least a write.
- Deadlocks: Constellations in which multiple threads block each other cyclically forever.
- Thread-unsafe usage: Unsynchronized concurrent calls or accesses of application programming interfaces that are not specified to be thread safe.
The abovementioned issues are all fundamental programming bugs that can lead to program errors. These issues occur non-deterministically, possibly sporadically or very seldom. They are therefore hard to identify in tests and are not easily reproducible. For this reason, it makes sense to use a static analysis that examines various program traces, including very specific or seldom cases, as to whether they suffer from such issues.
As a first starting point, you can try the sample C# solutions to detect data races and deadlocks.
You can download the samples from https://github.com/blaeser/parallelchecker/tree/main/doc/samples
How It Works
The checker is implemented based on the compiler framework Roslyn and analyzes the C# source code without executing the program, called static analysis. It screens as many interesting program traces as possible within defined deterministic bounds. The analysis maintains exact and complete context information for the program, where possible. Exceptions are e.g. external input/output and missing or incorrect source code parts, in which case conservative assumptions are made. The properties of the checker can be summarized as:
- Precise: Real issues are reported without false positives (no false alarms), except when making conservative assumptions.
- Incomplete: The checker may miss potential issues (possible false negatives) as there exists no precise and complete analysis.
- Deterministic: The same issues are repeatedly reported for the same program.
The checker engages a new algorithm. It has been designed to efficiently deal with large software projects and find as many issues with high precision as possible.
You can find more information on the checker website https://github.com/blaeser/parallelchecker