I have a Windows Form app in which a Windows Timer (when it ticks) starts a new thread to do a long running process.
During the execution of this thread, I am getting an error writing to a Logfile (also using a static class).
Anyway, I guess the problem is that multiple threads are attempting to write to the same log file, but after perusing online (and making numerous changes) , I am still getting the error (cannot access file as it is already in use).
Any help would be appreciated.
Code:
ThreadStart ts = new ThreadStart(Task.RunTask);
Thread thr = new Thread(ts);
thr.Start();
Code:
tw1 = TextWriter.Synchronized(File.AppendText(sLogFileName));
tw1.WriteLine(DataToWrite);
tw1.Flush();
Any help would be appreciated.
Comment