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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.