通过 GUI 访问 Windows 服务的最佳方式 [英] best way to access a windows service via GUI

查看:35
本文介绍了通过 GUI 访问 Windows 服务的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇 C# gui 访问 Windows 服务功能的最佳方式,无论是 WCF 或 ServiceController 还是其他一些选项.

I'm curious about the best way for a C# gui to access the functions of a Windows Service, be it WCF or ServiceController or some other option.

我将解释我在做什么:在规定的时间间隔内,该服务将从位置 A 压缩一小时的数据文件并将压缩文件发送到位置 B,这将在后台 24/7 中完成或者直到服务被用户停止并且即使没有人登录也能运行(因此需要服务)我希望用户能够启动一个 GUI 程序,允许他们有几个选项:

I'll explain what I'm doing: on a regulated time interval the service will be zipping one hours worth of datafiles from location A and sending the zipped file to location B, this will be done in the background 24/7 or until the service is stopped by the user and runs even when no one is logged in (hence the need for service) I would like the user to be able to pull up a GUI program that will allow them several options:

1) 将位置更改为 zip from
2) 将位置更改为 zip to
3) 手动启动指定日期时间范围的压缩过程

1) change the location to zip from
2) change the location to zip to
3) manually start the zipping process for a DateTime range specified

现在大部分压缩和计时器功能都存储在服务中.所以我想知道 GUI 程序中的 ServiceController 是否允许我向/从服务发送变量(即文件夹路径名称作为字符串,各种其他数据),或者我是否需要花时间制作 WCF 并将 GUI 视为客户端和 Windows 服务作为源.

Now most of the functions for zipping and timers is all stored within the service. SO im wondering if a ServiceController in the GUI program would allow me to send variables to/from the service (ie folderpath names as strings, various other data) or if I'll need to spend the time making a WCF and treat the GUI as the Client and the Windows service as a source.

应该注意的是,GUI 可能会从服务接收数据,但仅表示当前正在忙于压缩.

It should be noted the GUI will likely recieve data from the service, but only to signify if it is currently busy zipping.

推荐答案

一种选择是将 WCF 服务嵌入到您的 Windows 服务中.使用此 WCF,您无需重新启动服务即可控制行为.

One option is to tave a WCF service embedded on your windows service. With this WCF you can control the behaviour without restarting the service.

但 IMO 的最佳选择是将其包含在配置文件中.您可以添加一些密钥,但在更新配置时必须重新启动服务.在这种情况下,您可以尝试一种解决方法,如此线程.配置是处理此类细节的好地方,因为它可以轻松修改,而且与数据库不同,它始终可用.

But the best option IMO is to have this in a config file. You can add some keys, but you would have to restart the service when you update the config. In this case you can try a workaround, as in this thread. The config is a good place for this kind of detail, because it can be easily modified and, unlike a database, it will be always avaiable.

这篇关于通过 GUI 访问 Windows 服务的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆