本文介绍了“StreamWriter.WriteLine()”函数需要“lock()”吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了一个写日志的类。它用StreamWriter.WriteLine()函数写。
logStream.WriteLine(msgWrite);
logStream.Flush();
一些不同的线程使用这个类来编写日志,在一个文本文件中(日志文件对所有线程都是通用的)它需要lock()函数吗? />
我应该更改我的代码吗?
lock(syncObj)
{
logStream.WriteLine(msgWrite);
logStream.Flush();
}
请帮帮我。
解决方案
Hi,
i develop a class to write logs. it writes with "StreamWriter.WriteLine()" function.
logStream.WriteLine(msgWrite);
logStream.Flush();
some different threads use this class to write logs, in one text file(The log file is common for all threads) do it need to lock() function?
should i change my code?
lock(syncObj)
{
logStream.WriteLine(msgWrite);
logStream.Flush();
}
please help me.
解决方案
这篇关于“StreamWriter.WriteLine()”函数需要“lock()”吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!