windows服务-监视文件

配置一个xml其中有是否开启监视、监视时间、监视路径。

      FileSystemWatcher watcherName = new FileSystemWatcher();
            watcherName.IncludeSubdirectories = false;
            watcherName.Filter = "*.txt";
            watcherName.Path = ulrValue + @"";
            watcherName.Created += new FileSystemEventHandler(watcherName_Created);//新增事件
       //
watcherName存在 删除 修该 更改文件名的事件
       watcherName.EnableRaisingEvents = true;

启动服务需要注册服务,再到计算机中的管理中的服务中找到去的名称的服务启动

注册:C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/InstallUtil.exe(InstallUtil.exe程序) + (服务代码生成的exe程序)。

ResService.cs程序右键点击’添加安装程序‘ 然后Account 是准备什么类型的服务,ServiceName 是服务名称。

原文地址:https://www.cnblogs.com/bit-by-bit/p/3880517.html