1

我开发了一个 Windows 服务应用程序。该服务所做的只是启动 filewatcher 并侦听正在创建的 .csv 文件,然后处理该文件。之前我们使用应用程序文件夹进行监控,但由于需要安全权限才能将文件复制到应用程序根目录中,我们决定将其路径更改为 My Documents 文件夹。在安装过程中安装程序完成后,将在 My Documents 文件夹下创建 ProductName 文件夹。(存档文件夹也在 ProductName 文件夹下创建。)安装后,我们有一个类似 My Documents\ProductName\Archive\ 的结构

当我们尝试启动服务时,它会停止,我们可以在事件查看器中看到的唯一异常是:

异常信息:System.ArgumentException 堆栈:在 System.IO.FileSystemWatcher.set_Path(System.String)

public partial class ServiceName : ServiceBase
{
    private readonly IMachineResultProcessos _controler;
    private readonly FileSystemWatcher _watcher;
    private readonly string _rootpath = Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments),"ProductName");

    public ServiceName()
    {
        InitializeComponent();
        _controler = new DataProcessos();
        _watcher = new FileSystemWatcher
                       {
                           Path = _rootpath + @"\Archive",
                           Filter = "*.csv"
                       };

        _watcher.Created += OnFileCreated;
        _watcher.EnableRaisingEvents = true;
    }

}

它在调试下工作,但在客户端机器上部署时出现问题。

欢迎任何建议或想法。

4

0 回答 0