Locking
The simple threading example we’ve created so far works well because the two tasks work independently. If you need to communicate between threads, life is not as simple. Trying to access an object on more than one thread at once is inherently dangerous. Threading problems are also infamously hard to diagnose because a single command in a high-level language such as Visual Basic .NET might actually compile to dozens of low-level machine-language instructions.
Locking enables you to obtain exclusive access to an object that’s used by another thread. You can then safely modify the value without worrying that another thread might try to read or change it while your operation is in progress. Locking is built into Visual Basic .NET through the ...
Get Microsoft® .NET Distributed Applications: Integrating XML Web Services and .NET Remoting 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.