O'Reilly logo

Microsoft® .NET Compact Framework Kick Start by Ronnie Yates, Erik Rubin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Controlling Access to Data Objects with the Monitor Class

The Monitor class provides another synchronization mechanism available in the .NET Compact Framework. The Monitor class is useful for protecting access to specific objects. You can use a Monitor to make sure that only one thread accesses a specific object at a time. This intent is subtly different from using a Mutex, which you can use to prevent two threads from executing a specific block of code at one time.

To use a Monitor to prevent multiple threads from accessing the same object, follow these steps:

1.
Acquire the object that you want to protect. When you want to access the protected object, first call System.Threading.Monitor.Enter(). Pass in the reference to the object to protect. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required