如何使GUI等待Windows服务? [英] How to make GUI wait for windows service?

查看:44
本文介绍了如何使GUI等待Windows服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个Windows服务和一个GUI.当然,gui主要取决于服务.gui是否有办法等待服务?有时我需要从gui重新加载服务配置并重新启动服务.

I wrote a windows service and a gui for it. Of course gui mainly depends on the service. Is there a way for gui to wait for the service? Sometimes I need to reload service config from the gui and restart the service.

我正在考虑2种解决方案:1.使用while和sleep等待服务控制器状态更改(当然,最简单的解决方案是:P)2.在某个位置的INotifiPropertyChanged接口中实现(对于这个琐碎的问题,这看起来很复杂).

I was thinking about 2 solutions: 1. using while and sleep to wait for service controller status to change (of course the simplest solution :P) 2. implementin INotifiPropertyChanged interface somewhere (this looks to complicated for this trivial problem).

我想知道是否还有更优雅的方法?我在某处失踪了吗?

I was wondering is there more elegant way of doing it? Is there an event that I am missing somewhere?

推荐答案

ServiceController具有WaitForStatus方法,可在其中向其传递ServiceControllerStatus类型的参数.您可以像这样使用它:

ServiceController has a method WaitForStatus where you pass it an argument of type ServiceControllerStatus. You can use it like this:

controller.WaitForStatus(ServiceControllerStatus.Running);

这篇关于如何使GUI等待Windows服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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