[英]Error 1053:The service did not respond to start or control request in timely fashion with FileSystemWatcher
I have created a Windows Service which uses a FileSystemWatcher to look for changes in different directories.我创建了一个 Windows 服务,它使用 FileSystemWatcher 来查找不同目录中的更改。 When I launch the service I am getting the error:
当我启动服务时,我收到错误:
Error 1053:The service did not respond to start or control request in timely fashion.
I think that the error is coming from an infinite loop caused by using the using
statement in the Watch() method as shown below:我认为错误来自在 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;
}
This is my OnStart() method:这是我的 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();
}
Can you please help me to find a solution to this issue?你能帮我找到解决这个问题的方法吗? I have tried a lot of suggestions but they don't seem to work.
我尝试了很多建议,但它们似乎不起作用。 Thank you!
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.