111,129
社区成员
发帖
与我相关
我的任务
分享
private object lockTemp=New object();
public static void WriteLog(string msg)
{
lock(lockTemp)
{
StreamWriter sw = null;
string log = "c:\\log.txt";
try
{
sw = System.IO.File.AppendText(log);
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss: ") + msg);
sw.Flush();
}
}
catch
{
}
finally
{
sw.Close();
}
}
你的多线程代码呢??
public static void WriteLog(string msg)
{
StreamWriter sw = null;
string log = "c:\\log.txt";
try
{
sw = System.IO.File.AppendText(log);
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss: ") + msg);
sw.Flush();
}
catch
{
}
finally
{
sw.Close();
}
}