Change your code as follows:
1) Give the Mutex the name
@"Global\MyMutex"
.
2) Call
Dispose()
on
w
after (or instead of)
Close()
.
Do the same for your other process.
[EDIT]
I would simplify the code as follows:
public class Log
{
public static Mutex m_Mutex = new Mutex( false, @"Global\MyMutex" );
public static void LogStuff( string stuff )
{
try
{
m_Mutex.WaitOne();
using(var w = File.AppendText( @"C:\temp.log" ))
{
w.WriteLine( stuff );
}
}
finally
{
m_Mutex.ReleaseMutex();
}
}
}
This
using
block calls the Dispose at the end of the block (thus, flushing and closing the stream and releaseing the proxy object of the file on the file system).
[/EDIT]
Cheers
Andi