如何解决将行插入表时通知窗口服务
我已经构建了一个Windows服务,该服务始终使用FileSystemWatcher
列出不同文件夹位置上的文件引发的事件。我正在使用OnStart
方法从SQL数据库中获取文件夹位置的列表,因为OnStart
的代码如下所示。
public void OnStart()
{
try
{
// get the folder location list from Database
var getListOfFOlderLocation = DbHelper.GetFolderList();
// Get the maximum number of concurrent processes that can be active (if specified)
if (ConfigurationManager.AppSettings["maxConcurrentProcesses"] != null)
maxConcurrentProcesses = Convert.ToUInt32(ConfigurationManager.AppSettings["maxConcurrentProcesses"]);
// Instantiate the regulation semaphore to enforce the maximum process count
executionRegulator = new SemaphoreCounter(maxConcurrentProcesses);
// System.Diagnostics.Debugger.Launch();
// loop though in multiple directories to monitor files
foreach (string sMonitorFolder in DirectoryToWatch())
{
// Create and instantiate an individual FileSystemWatcher for each file set
FileSystemWatcher fileSysetmWatcher = new System.IO.FileSystemWatcher(sMonitorFolder);
if (Directory.Exists(sMonitorFolder))//make sure that mentioned directories exists
{
fileSysetmWatcher.Path = sMonitorFolder;
fileSysetmWatcher.Filter = "*.*";
fileSysetmWatcher.IncludeSubdirectories = true;
fileSysetmWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.DirectoryName;
fileSysetmWatcher.Created += new FileSystemEventHandler(fileSysetmWatcher_created);
fileSysetmWatcher.EnableRaisingEvents = true;
}
}
new System.Threading.AutoResetEvent(false).WaitOne();
}
catch (Exception ex)
{
Global.WriteLog("Error: " + ex.Message);
}
}
一切正常,如果文件到达特定位置,我会得到更新。
问题/要求:假设服务正在服务器上运行,现在我想添加更多要监视的文件夹,而不是如何让服务知道该表中的更多文件夹列表已被更新。
请让我知道之前是否有人这样做过。
到目前为止,更新表后,我正在执行启动/停止服务以获取更新的文件夹监视列表,这显然不是一个好选择。
我正在寻找做到这一点的最佳方法。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。