监视多个文件,从 Windows 启动开始 [英] Monitoring of multiple files, starting from Windows boot

查看:41
本文介绍了监视多个文件,从 Windows 启动开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个程序来进行标记"(在我的情况下它们实际上不是标记)Windows 文件、放置描述等.语言:C#.我需要一些指南来监视所有这些标记"文件,以便在它们被重命名、移动、删除时获得通知.我想从 Windows 启动到用户关闭 PC 的那一刻监视它们.我已经检查了这个 FileSystemWatcher 类,但仍然:

I'm trying to make a program for sort of "tagging" (in my case they are not tags actually) Windows files, putting descriptions etc. Language: C#. I need somewhat of a guideline for a way to monitor all these "tagged" files, to get notifications in case they're renamed,moved,deleted. And I want to monitor them from the time Windows boots til the moment the user shuts the PC down. I've checked this FileSystemWatcher class, but still:

  • 为我想要关注的每个文件创建一个单独的此类实例是否是个好主意?
  • 它实际上是我应该为此功能制作的 Windows 服务吗?

我非常乐意就我的最佳方法获得任何建议.

I'll be more than happy to get any advice on what my approach is best to be.

推荐答案

您应该使用 FileSystemWatcher 来监视目录(以及可能的子目录).它将收到监视目录中所有文件更改的通知.然后,您可以过滤要观看的单个文件.

You should use the FileSystemWatcher to watch a directory (and, potentially, subdirectories). It will be notified of changes to all files in the watched directories. You can then filter for the individual files you want to watch.

我会为您想要查看的每个顶级目录推荐一个 FileSystemWatcher.因此,如果您正在观看:

I would suggest one FileSystemWatcher for each top-level directory you want to watch. So if you're watching:

/dir1
/dir1/subdir
/dir1/subdir/sub-subdir
/dir2

那么您将有两个 FileSystemWatcher 组件:一个用于 dir1,另一个用于 dir2

Then you'd have two FileSystemWatcher components: one for dir1, and one for dir2

Windows 服务是此工具的不错选择.另一个不错的选择是在启动时作为计划任务运行的控制台应用程序.计划任务的好处是让您可以更轻松地启动和停止它.这可能是您想要进行初始开发的方式.将控制台应用程序转换为服务非常容易.

A Windows service is a good selection for this tool. Another good selection would be a console application that is run at startup as a scheduled task. The scheduled task has the benefit of letting you start and stop it more easily. Which might be the way you want to go for initial development. It's pretty easy to convert a console application to a service.

这篇关于监视多个文件,从 Windows 启动开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆