Windows服务:FileWatcher路径已更改 [英] Windows Service : FileWatcher path changed
本文介绍了Windows服务:FileWatcher路径已更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在windows服务OnStart方法中有filewatcher来查找特定的目录或文件夹路径并处理文件...等等等等等等......我从其他应用程序中读取此路径并且效果很好。
我启动了我的Windows服务,一切正常。但是,在某段时间之后 如果路径已经从用户更改,我将如何在不停止服务的情况下将此新路径发送到Windows服务中的文件观察器?
谢谢!
I have filewatcher in windows service OnStart method to look for particular directory or folder path and process files... blah blah blah.... This path I am reading from other application and it works well.
I start my windows service and it all works well. However, after sometime, if path has changed from user, how would I achieve to send this new path to file watcher in windows service without stopping the service?
Thanks !
推荐答案
得到解决方案,...我刚刚在Windows的Start事件中使用了一个计时器,它将调用特定的特定方法间隔,并且我正在检查我的更新路径。
私人计时器作为新计时器()
受保护的覆盖Sub OnStart(ByVal args()As String)
AddHandler timer.Elapsed,AddressOf Path_Changed
timer.Interval = 10000
timer .AutoReset = True
timer.Enabled = True
timer.Start()
End Sub
Private Sub Path_Changed(发送者作为对象,e作为EventArgs)
Dim GeneralSettings作为新词典(字符串,对象)
Dim myClientSetti ngs为New My_WCFService.MyService
GeneralSettings = myClientSettings.GetMyClientSettings()
FSWatcher.Path = GeneralSettings(InputFolder)
End Sub
Got the solution,... I have just used a timer in my Start event of windows which will call particular method in specific interval, and in that I am checking my updated path.
Private timer As New Timer()
Protected Overrides Sub OnStart(ByVal args() As String)
AddHandler timer.Elapsed, AddressOf Path_Changed
timer.Interval = 10000
timer.AutoReset = True
timer.Enabled = True
timer.Start()
End Sub
Private Sub Path_Changed(sender As Object, e As EventArgs)
Dim GeneralSettings As New Dictionary(Of String, Object)
Dim myClientSettings As New My_WCFService.MyService
GeneralSettings = myClientSettings.GetMyClientSettings()
FSWatcher.Path = GeneralSettings("InputFolder")
End Sub
谢谢大家的帮助!
这篇关于Windows服务:FileWatcher路径已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文