微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Service.Controller状态/轮询

我正在处理一个pipe理应用程序的问题。 我构build了一个接口,用于停止,启动和查询40多台服务器上的各种服务。

我正在查看service.controller,并成功地停止和启动各种button事件的服务,但现在我试图找出一种方法来返回服务状态的文本框,并每10秒查询服务状态或所以我觉得我正在打砖墙。

有没有人有任何提示或见解?

谢谢!!

一个提升的进程中打开一个非提升浏览器的网页C#

将sockaddr中的IP地址转换为uint32_t

发布一个程序

在运行configure时configuration不同于认值的编译器

尝试使用execvpe(…)但得到隐式声明错误 – 即使我想我使用正确的参数types

如何调用在C#中的Windows屏幕保护程序?

在webview(UWP)中启用触摸事件

增强库…预先构build的变种?

是所有parsing器与yacc或野牛(和lex / flex)?

在Linux中着色的控制台输出

您可以使用Timer对象触发定期服务检查。 您可以在Elapsed事件上运行您的服务查询

private void t_Elapsed(object sender,ElapsedEventArgs e) { // Check service statuses }

至于在文本框中显示状态,你应该可以在服务状态上使用ToString()方法,并在普通文本框中显示。 请记住,在对定时器事件作出反应时,您可能会或可能不在GUI线程上,因此您需要自行调用主线程。

private delegate void TextUpdateHandler(string updatedText); private void UpdateserverStatuses(string statuses) { if (this.Invokerequired) { TextUpdateHandler update = new TextUpdateHandler(this.UpdateserverStatuses); this.BeginInvoke(update,statuses); } else { // load textBox here } }

也许你不想投票:

Private serviceController As ServiceController = nothing Private serviceControllerStatusRunning = False Private Sub Form1_Load(sender As Object,e As System.EventArgs) Handles Me.Load Try serviceController = New ServiceController("NameOfTheTheServiceYouWant") If serviceController.Status = ServiceControllerStatus.Stopped Then ' put code for stopped status here Else ' put code for running status here End If BackgroundWorker1.RunWorkerAsync() Catch ex As Exception MessageBox.Show("error:" + ex.Message) serviceController = nothing Me.Close() Exit Sub End Try End Sub Private Sub BackgroundWorker1_DoWork(sender As System.Object,e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork If serviceControllerStatusRunning Then serviceController.WaitForStatus(ServiceControllerStatus.Stopped) serviceControllerStatusRunning = False Else serviceController.WaitForStatus(ServiceControllerStatus.Running) serviceControllerStatusRunning = True End If End Sub Private Sub BackgroundWorker1_RunWorkerCompleted(sender As System.Object,e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted if serviceControllerStatusRunning then ' put code for running status here else ' put code for stopped status here end if BackgroundWorker1.RunWorkerAsync() ' start worker thread again End Sub

欢呼进化

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐