private void btnStart_Click(object sender, System.EventArgs e)
{
Thread td=new Thread(new ThreadStart(WatchFile));
td.Start();
FileChange(null,null);
}
private void WatchFile()
{
FileSystemWatcher fsw=new FileSystemWatcher();
fsw.Filter="*.log";
fsw.IncludeSubdirectories=false;
fsw.Path=@"D:\";
fsw.Changed +=new FileSystemEventHandler(this.FileChange);
fsw.EnableRaisingEvents=true;
} public void FileChange(Object source,FileSystemEventArgs e)
{
try
{
txtContent.Clear();
StreamReader sr=new StreamReader(@"D:\AAA.log");
string line;
while((line=sr.ReadLine())!=null)
{
txtContent.AppendText(line + "\r\n");
}
}
catch(Exception ex)
{
string sdfgasdf=ex.Message;
}
}上面是我写的监听文件改变的。功能能实现。或是为什么只我的设置上了监听。这个文件就不能再修改了呢?我读的时候也就出错了。谢谢!
{
Thread td=new Thread(new ThreadStart(WatchFile));
td.Start();
FileChange(null,null);
}
private void WatchFile()
{
FileSystemWatcher fsw=new FileSystemWatcher();
fsw.Filter="*.log";
fsw.IncludeSubdirectories=false;
fsw.Path=@"D:\";
fsw.Changed +=new FileSystemEventHandler(this.FileChange);
fsw.EnableRaisingEvents=true;
} public void FileChange(Object source,FileSystemEventArgs e)
{
try
{
txtContent.Clear();
StreamReader sr=new StreamReader(@"D:\AAA.log");
string line;
while((line=sr.ReadLine())!=null)
{
txtContent.AppendText(line + "\r\n");
}
}
catch(Exception ex)
{
string sdfgasdf=ex.Message;
}
}上面是我写的监听文件改变的。功能能实现。或是为什么只我的设置上了监听。这个文件就不能再修改了呢?我读的时候也就出错了。谢谢!
解决方案 »
- 我的IE8不支持html框架,请问怎样解决
- 关于清空密码框的问题
- 如何用IIS调试VS中的ASP.NET程序
- 按钮被Enable=false后依然执行OnClientClick
- Vs2005水晶报表 导出excel提示内存不足以完成操作,求助?
- dataset,datatable和dataview都是放在服务器内存???
- csc不产生程序集清单,是什么原因?50分求助
- 配置UrlRewriting后AutoCompleteExtender无效。。怎么回事
- SharePoint2003中多文件上传页面无法响应????
- ASP.net localhost 端口设置
- 如何用vs2003对web程序(C#)打包?
- 看书过程中,有一处想不明白.马上结帐
为什么在td.Start();之后要FileChange(null,null);你是想实现怎么的功能?
AAA.Log文件已经被占用了