avatar
easy question, but ...# DotNet - 窗口里的风景
c*o
1
Many users will write to the same logfile, how can I make sure there is no
conflict when there are some concurrent access? I can't find a method to check
if the file is open or not.
Would you please add some sample code based on the following code? Thank you
so much!
StreamWriter sw=File.AppendText (sLogFile);
sw.WriteLine (DateTime.Now.ToLongTimeString ()+" "+sText);
sw.Flush ();
sw.Close ();
avatar
k*i
2
when you create or open the file

check

【在 c*o 的大作中提到】
: Many users will write to the same logfile, how can I make sure there is no
: conflict when there are some concurrent access? I can't find a method to check
: if the file is open or not.
: Would you please add some sample code based on the following code? Thank you
: so much!
: StreamWriter sw=File.AppendText (sLogFile);
: sw.WriteLine (DateTime.Now.ToLongTimeString ()+" "+sText);
: sw.Flush ();
: sw.Close ();

avatar
e*s
3
open it exclusively for write;
or creating a reader/writer threading model to handle concurrency conflicts...
this is a very typical situation

check

【在 c*o 的大作中提到】
: Many users will write to the same logfile, how can I make sure there is no
: conflict when there are some concurrent access? I can't find a method to check
: if the file is open or not.
: Would you please add some sample code based on the following code? Thank you
: so much!
: StreamWriter sw=File.AppendText (sLogFile);
: sw.WriteLine (DateTime.Now.ToLongTimeString ()+" "+sText);
: sw.Flush ();
: sw.Close ();

avatar
G*T
4

conflicts...
hehe,
VB .NET has eventlog class, u can use it to write system log or ur own log
files.
you

【在 e*********s 的大作中提到】
: open it exclusively for write;
: or creating a reader/writer threading model to handle concurrency conflicts...
: this is a very typical situation
:
: check

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。