Difference between synclock and mutex

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I'm new to multithreading applications in .NET. What exactly is the difference between using synclock on a variable or using mutex.waitone/mutex.releasemutex
There is too much stuff out there on multithreading and I can't find a simple answer
Also, is this a "normal" way of writing to files in multithreading applications

Dim objReader As StreamWrite
SyncLock (objReader
objReader = New StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory & ERR_FILE_NAME
objReader.Write(some message
objReader.Close(
End SyncLoc

Thank
JS
 
SyncLock is just a language shortcut for using the Monitor class and
its Enter and Exit methods.

The main difference between Monitor and Mutex is that Mutex wraps the
native Win32 mutex, so it can be used across processes and to
synchronize managed and native code. Monitor is only for managed code
and for use within the same appdomain.



Mattias
 
Back
Top