CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
Like the ManualResetEvent and the AutoResetEvent classes, the Mutex class is also derived from the WaitHandle class. It is very similar to the Monitor class with the exception that it can be used for interprocess synchronization. Let's look at an example, WroxMutex.cs:
The output from WroxMutex is:
Thread will sleep for 5 secondsIn
WroxMutex,
we construct a Mutex
with a Boolean value indicating that the calling thread should have initial
ownership of the Mutex,
and a string that is the name of the Mutex. We then create a thread, which calls
the Run()
method. The Mutex
is still owned by the main thread. In the Run() method, the thread t has to
wait until the main thread releases the ownership of the Mutex. Thus, the thread t waits
at the WaitOne()
method call in the Run()
method. After sleeping for five seconds, the main thread releases the Mutex
lock. Thread t
then gets the ownership of the Mutex lock and then goes off for a sleep. Now,
the
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 693
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved