Shu*_*ing 7 c# visual-studio-2013
我刚刚将Visual Studio升级到版本2013 Ultimate,我发现System.IO.FileSystemWatcher
类无法观看由Visual Studio 2013编辑的文件.假设我有以下代码
class Program
{
static void Main(string[] args)
{
var watcher = new FileSystemWatcher(@"C:\test", "*.txt");
watcher.Changed += watcher_Changed;
watcher.EnableRaisingEvents = true;
Console.Read();
watcher.Changed -= watcher_Changed;
}
static void watcher_Changed(object sender, FileSystemEventArgs e)
{
Console.WriteLine("file is changed");
}
}
Run Code Online (Sandbox Code Playgroud)
如果我C:\test\a.txt
用记事本编辑文件,程序将报告文件是更改,但如果我使用Visual Studio 2013编辑它,我的程序保持沉默.为什么?
小智 8
我注意到在Visual Studio 2013中编辑文件时,它会创建临时文件,然后删除原始文件并将临时文件重命名为相同的名称.因此,要赶上正常编辑处理System.IO.FileSystemWatcher
的Changed
事件,在Visual Studio中的编辑,处理该Renamed
事件.
我检查了Marcus和Shuping的解决方案,但在我的情况下,他们没有工作.我为解决这个问题所做的就是设置:
watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime;
Run Code Online (Sandbox Code Playgroud)
在那个Changed
事件开始工作之后.
VS 2013版: 12.0.30501.00 Update 2
归档时间: |
|
查看次数: |
1660 次 |
最近记录: |