[英]Re-create folder after re-start of window service using Topshelf
I am using Topshelf
for window service and I used configuration AfterInstall
to create a folder CreateFolder
. 我正在将
Topshelf
用于窗口服务,并且使用了AfterInstall
配置来创建文件夹CreateFolder
。
Now when I install/start service, the folder gets created. 现在,当我安装/启动服务时,将创建文件夹。 Nice!
太好了!
lets say after some time I stopped my service and delete the folder which creates, then upon re-start of service, I want to folder to be re-created. 可以说一段时间后,我停止了服务并删除了创建的文件夹,然后在重新启动服务后,我想重新创建文件夹。 Is this possible?
这可能吗?
Is there any setting within Topshelf
configuration so that on re-start of service folder will create again? Topshelf
配置中是否有任何设置,以便在重新启动服务文件夹时会再次创建?
HostFactory.Run(
configuration =>
{
configuration.AfterInstall(CreateFolder);
configuration.Service<Service1>(
service =>
{
service.ConstructUsing(x => new Service1());
service.WhenStarted(x => x.Start());
service.WhenStopped(x => x.Stop());
});
configuration.EnableServiceRecovery(recoveryOption =>
{
recoveryOption.RestartService(1);
});
configuration.RunAsVirtualServiceAccount();
configuration.SetServiceName("TEST");
configuration.StartAutomatically();
"CreateFolder" Method below here, 下面的“ CreateFolder”方法,
static void CreateFolder()
{
Directory.CreateDirectory(some path);
}
TopShelf only has custom actions for the AfterInstall. TopShelf仅对AfterInstall具有自定义操作。 You could tie into the service Start() function to check for and create the directory using the Directory.CreateDirectory(path) method.
您可以绑定到服务Start()函数,以使用Directory.CreateDirectory(path)方法检查并创建目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.