微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

错误 1053:服务未通过 FileSystemWatcher 及时响应启动或控制请求

如何解决错误 1053:服务未通过 FileSystemWatcher 及时响应启动或控制请求

我创建了一个 Windows 服务,它使用 FileSystemWatcher 来查找不同目录中的更改。当我启动服务时出现错误

Error 1053:The service did not respond to start or control request in timely fashion.

我认为错误来自在 Watch() 方法中使用 using 语句导致的无限循环,如下所示:

    public FileSystemWatcher Watch()
    {

        FileSystemWatcher watcher;
        using (watcher = new FileSystemWatcher($"C:\\Users\\lashi\\AppData\\Roaming\\Sublime Text 3",_ext))
        {
           
            watcher.NotifyFilter = NotifyFilters.LastAccess
                                 | NotifyFilters.LastWrite
                                 | NotifyFilters.FileName
                                 | NotifyFilters.DirectoryName;

            watcher.IncludeSubdirectories = true;
            // Add event handlers.
            watcher.Changed += OnChanged;
            watcher.Created += OnChanged;
            watcher.Deleted += OnChanged;
            watcher.Renamed += OnRenamed;

            // Begin watching.
            watcher.EnableRaisingEvents = true;

        }
        return watcher;
    }

这是我的 OnStart() 方法

    protected override void OnStart(string[] args)
    {
        String userName;
        String expt;
        if (args.Length < 2)
        {
            Console.WriteLine($"FileWatcher <user> <exptName>");
            Console.WriteLine($"Captures files into /temp/<exptName>-log and /temp/<exptName>-files");
            userName = "wost";
            expt = "expt1";
        }
        else
        {
            userName = args[0];
            expt = args[1];
        }
        String lexpt = $"C:\\Users\\lashi\\Desktop\\emmC_CACHE\\{expt}-log";
        String fexpt = $"C:\\Users\\lashi\\Desktop\\emmC_CACHE\\{expt}-file";

        if (!Directory.Exists(fexpt))
        {
            Directory.CreateDirectory(fexpt);
        }
        if (!Directory.Exists(lexpt))
        {
            Directory.CreateDirectory(lexpt);
        }
        // File Watcher Launch
        Watcher w = new Watcher(lexpt,fexpt,userName);
        FileSystemWatcher fw = w.Watch();
    }

你能帮我找到这个问题的解决方案吗?我尝试了很多建议,但它们似乎不起作用。谢谢!

解决方法

点击here!查看如何通过编辑注册表项来增加 Windows 服务管道超时

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。