public class Demo {
private static ReaderWriterLockSlim _readWriteLock = new ReaderWriterLockSlim();
public void WriteToFileThreadSafe(string text, string path) {
// Set Status to Locked
_readWriteLock.EnterWriteLock();
try
{
// Append text to the file
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine(text);
sw.Close();
}
}
finally
{
// Release lock
_readWriteLock.ExitWriteLock();
}
}
}
Kaynak: http://www.johandorper.com/log/thread-safe-file-writing-csharpReklam: www.evrenpehlivan.com