当我打开文件以解压缩其内容时,出现以下异常。当我在 Windows 资源管理器中选择文件或将鼠标悬停在显示工具提示的文件上时,就会发生这种情况。
System.IO.IOException was unhandled
Message=The process cannot access the file 'D:\Documents\AutoUnZip\Zips\MVCContrib.Extras.release.zip' because it is being used by another process.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.OpenRead(String path)
at AutoUnzip.SelectFolderForm.w_Changed(Object sender, FileSystemEventArgs e) in D:\Projects\WindowsForms\AutoUnzip\AutoUnzip\SelectFolderForm.cs:line 37
at System.IO.FileSystemWatcher.OnCreated(FileSystemEventArgs e)
at System.IO.FileSystemWatcher.NotifyFileSystemEventArgs(Int32 action, String name)
at …Run Code Online (Sandbox Code Playgroud) 是否可以配置 aFileSystemWatcher以查看与文件夹连接点链接的其他文件夹?
例如:
你在看 D:
你有 D:\junction 指向 E:\folder
当我在 E:\folder\file.txt 中创建一个文件时,我想在观察者中看到它作为 D:\junction\file.txt。
这可能吗?
谢谢。
使用FileSystemWatcher,是否有办法在事件触发后处理事件侦听器的实例?
我的程序基本上监听在新创建的文件夹中创建batch.complete.xml文件.程序检测到文件已创建后,无需继续侦听此文件夹.
我的程序看起来像这样:
public static void watchxmlfile(batchfolderpath){
var deliverycompletewatcher = new FileSystemWatcher();
deliverycompletewatcher.Path = batchfolderpath;
deliverycompletewatcher.Filter = "*.xml";
deliverycompletewatcher.Created += new FileSystemEventHandler(OnChanged);
deliverycompletewatcher.EnableRaisingEvents = true;
}
private static void OnChanged(object sender, FileSystemEventArgs e)
{
BuildingestionXml(string.Format(@"{0}\{1}",e.FullPath,e.Name));
Console.WriteLine(@"Second: Success sending{0}\{1}", e.FullPath, e.Name);
}
Run Code Online (Sandbox Code Playgroud)
因此,当上述事件被触发时,我不再需要在"batchfolderpath"中监视事件,除非显式调用watchxmlfile(),它将具有新路径.
我试图防止上述事件的过多侦听器实例的内存泄漏.
在我的 FileSystemWatcher 超过 5 分钟没有收到任何更改后,我试图让一些代码触发。
我目前的方法是await Task.Delay();在更改后调用 a ,希望用户到时完成。这显然不是要走的路。
所以我的问题是:如何在事件触发后重置 Task.Delay()?
我已经配置了一个FileSystemWatcher,以便它在一个文件夹上观察C:\folder.
当我将其正在观看的文件夹的名称更改为另一个文件夹时,它突然出现问题,并且它不会引发任何问题.
问题是:FileSystemWatcher如果对正在观察的同一个"对象"进行更改,是否会引发某些事件?
我想创建一个Reactive Observable,它可以同时观察Renamed和。Changed
我正在监视文件夹中是否有已修改和重命名的文件FileSystemWatcher。我只想在事件稳定下来后处理该事件(因为有时Changed事件可能会引发多次)。所以我选择Throttle.net的功能Reactive Extension。
我可以通过观察单个Changed事件来完成这项工作,但无法弄清楚如何Changed在Renamed单个Observable.
这是我为单个Changed事件所做的事情:
var watcher = new FileSystemWatcher();
watcher.Path = "d:\\test";
var observable = Observable.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>(
ev => watcher.Changed += ev,
ev => watcher.Changed -= ev
);
var d = observable.Throttle(TimeSpan.FromSeconds(5))
.Subscribe(
a => Console.WriteLine($"Watcher type:{a.EventArgs.ChangeType }, file:{a.EventArgs.Name }, sender: {a.Sender}"),
ex => Console.WriteLine("observer error:" + ex.ToString()),
() => Console.WriteLine("observer complete.")
);
Run Code Online (Sandbox Code Playgroud)
但是当我想观看这两个事件时,VS 告诉我 …
我想知道使用FileSystemWatcher类观察文件/目录是否是非常耗费内存的.我正在用C#开发一个桌面应用程序,它将在低性能计算机上不断地在幕后运行,我需要一些方法来检查各种文件是否已经改变.我可以想到几个解决方案:
有什么建议?
谢谢!
badPanda
我有一组文件,我想监视它们的变化.
我已经尝试过FileSystemWatcher类,但似乎在更改文件然后保存之后会触发通知.比方说,如果我监视目录中的.txt文件的变化,打开一些文件,保存它FileSystemWatcher工作.但是,如何在打开文件时键入更改并在不保存的情况下键入内容?首先阅读原文,然后在一段时间后读取相同的文件然后比较它们似乎很慢而且很愚蠢.有没有一种很好的方法来监控这种情况?
我正在构建一个使用FileSystemWatcher的Windows服务,并在后台运行.
我不希望每次想要调试时都继续卸载和安装服务,因此在将其转换为服务之前,我希望在正常程序中进行大部分开发.但是我对此很新,当我运行它时,它只是通过块然后退出.
什么是保持程序运行的好方法?
我的程序需要监视多个位置,但是为每个位置触发相同的代码.由于单个FileSystemWatcher无法监控多个位置,但是是否可以创建多个实例并为每个位置传递一个文件夹路径?
我不能对每个硬编码进行硬编码,FileSystemWatcher因为需要及时添加越来越多的位置,这需要由最终用户完成,因为FileSystemWatcher每次手动硬编码都是非常不切实际的.所以我的计划是将文件夹路径保存到文件中,程序只FileSystemWatcher为列表中的每个路径创建一个.但我不知道这是否有可能是最轻微的.
在这里进行工厂方法模式建议尝试:我得到错误:"'List'不包含'add'的定义
public void StartWatchers()
{
string[] ArrayPaths = new string[2];
List<FileSystemWatcher> watchers = new List<FileSystemWatcher>();
ArrayPaths[0] = @"K:\Daily Record Checker\Test\Test1";
ArrayPaths[1] = @"K:\Daily Record Checker\Test\Test2";
int i = 0;
foreach (String String in ArrayPaths)
{
watcher.add(MyWatcherFatory(ArrayPaths[i]));
i++;
}
//Do other stuff....
//....
//Start my watchers...
foreach (FileSystemWatcher watcher in watchers)
{
Watcher.EnableRaisingEvents = true;
i++;
}
}
FileSystemWatcher MyWatcherFatory(string path)
{
FileSystemWatcher watcher = new FileSystemWatcher(path);
watcher.Changed += Watcher_Created;
watcher.Path …Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×1
.net-core ×1
asp.net ×1
c++ ×1
delay ×1
directory ×1
file ×1
instance ×1
ioexception ×1
junction ×1
monitoring ×1
performance ×1
reset ×1
sharpziplib ×1
windows ×1