Loading color scheme

How to guarantee data consistency in multi-threaded environments?

If you are working in a multi-threaded environment, sooner or later you will stumble upon the situation with data corruption or exceptions due to unsynchronized access to common variables. For example, if you modify some member variable from two threads at the same time, there will be the so-called race conditions and the data may be inconsistent. To aid such a situation, you need to use an atomic lock object. The lock object in C# protects access to the variable from the different threads. Only one thread may access data at the same time.

Let's move to an example:

Read more
How to start several threads and wait them to finish in C#

If you need some work to be done in parallel, you will need to use threads. Usually, this work includes downloading some data from the server, processing multiple documents at once, launching several instances of the class at the same time, etc. 

But how do you start several threads at once? Here is the code example:

Read more
Get all interesting articles to your inbox
Please wait