I have a static function that write to a log file .
In my project I am already using multithreading ,
hense I m getting exception that
'process can't access file because it is being used by another process '
I want to mutex that code so that if one thread is accessing that code then another will have to wait.
Here is the code.
{
private static Mutex mut = new Mutex();
mut.WaitOne();
StreamWriter sw = new StreamWriter(path + "\\" + logFileName, true);
sw.WriteLine(stMessage);
sw.Close();
mut.ReleaseMutex();
}