i want to reach and write a txt file in cross-threads but software gives an exception because multiple threads wants to reach the same file at the same time. How can i invoke streamwriter to avoid exceptions? Here is my code:
void WriteLog(string LogStr)
{
StreamWriter sw = new StreamWriter("Log.txt", true);
sw.WriteLine(LogStr);
sw.Close();
}
I call WriteLog method in threads.
Thank you.
No comments:
Post a Comment