what is the difference between mutex and monitor implementation. Can any one please help me to learn both of these for wp7(implementable code for wp7). Please try to add some code snippets that help me to understand the techniques in a simple way. Thanx in advance Stezma
相关问题
- How do I create a multidimensional array of object
- An error is occur when we use navigation to move o
- Custom number picker?
- binding font-awesome character in XAML to Text
- Save Image to file keeping aspect ratio in a WPF a
相关文章
- Working with hmacsha256 in windows store app
- WP7 Alert dialog
- Add Service Reference and Add Web Reference?
- Can the “dynamic” type vary safely in a generic co
- Scrollviewer & SIP Issue (WP7.5 Mango)
- Check if a datetime is in same week as other datet
- Adding additional attributes to each property of a
- How to test handling of AccessViolationException
A mutex can lock across multiple processes. This would be useful in Windows Phone if you have a scheduled task running that needs exclusive access to a resource. In order to lock a mutex across processes the Mutex must be given a name.
A monitor can lock only within a process.
Mutex Example:
Phone App Task:
Scheduled Task class:
In the above example we're only allowing one app at a time access to the local database resource. This is why we'd use a Mutex.
Monitor Example (using lock syntax):
Phone App Task:
Scheduled Task class:
In this example we can stop more than one application thread entering SaveRow and we can stop more than one ScheduledTask thread from entering the DoStuff method. What we can't do with a Monitor is ensure that only one thread is accessing the local DB at once.
That's basically the difference. Monitor is much faster than a Mutex as well.