Multithreading Issues

Multithreading is a powerful technique that can improve the performance and responsiveness of your application. At the same time, multithreading introduces some complexities into your code that, if not properly attended to during the design and development cycle, may lead to disastrous results. In this section, we look at some important multithreading issues and the support .NET provides to handle them.

Shared Data Conflicts

If two threads have access to the same variable (more precisely, the same memory location), updating the variable from both the threads may leave the variable's value in an inconsistent state. Consider, for example, the following code:

 // Project SharedData\SharedDataConflict public class Foo { public ...

Get .NET Programming: A Practical Guide Using C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.