C#:GUI显示来自Windows服务的实时信息 [英] C#: GUI to display realtime messages from Windows Service

查看:194
本文介绍了C#:GUI显示来自Windows服务的实时信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个C#的窗口服务,可以写邮件到自定义事件日志或任意数量的文件。这些消息都标有一些优先级(因此,举例来说,只有错误和警告将存储在事件日志,但如果需要有更多可以存储到文件)。

I've written a C# windows service which can write messages to a custom EventLog or to any number of files. These messages are all marked with some priority (so, for example, only ERRORs and WARNINGs get stored in the EventLog, but if desired a lot more can be stored to a file).

我想现在要做的是创建一个图形用户界面,可以监听这些消息并实时显示。允许用户观看当前信息(在任何他们想要的优先级),而不需要的一切存储到文件中。我想这是某种形式的挂钩到服务一个单独的程序,但我不能确定从哪里开始。

What I'd like to do now is create a GUI that can listen for these messages and display them in real-time. Allowing a user to watch the current messages (at whatever their desired priority level), without the need to store everything to a file. I assume this is a separate program with some form of hook into the service, but I'm unsure of where to start.

这是我第一次真正的Windows服务,所以我似乎缺少一些关键字找出如何做到这一点?是否有任何code样本,教程,参考文献等,为如何做这样的事此?

This is my first real windows service, so I seem to be missing some keywords for finding out how to do this... Are there any code samples, tutorials, references, etc. for how to do something like this?

更新结果
很多有用的答案,我喜欢它,当有许多办法来解决问题!我想我会实现一个自托管WCF基础的解决方案。我还是在细节上很轻,因为我正在努力学习WCF(我相信它会证明我在其他项目中非常有用)...但迄今为止,我已经找到了视频的here 是最有用的作为介绍如何做。

UPDATE
A lot of helpful answers, I love it when there's many ways to solve a problem! I think I'm going to implement a self-hosting WCF based solution. I'm still very light on the details as I'm trying to learn about WCF (I believe it will prove quite useful for me in other projects)... but thus far, I've found the videos here to be the most helpful as an intro how-to.

推荐答案

你可以做的是有窗口服务在注册的事件(您可以通过使用Windows Communication Foundation的做到这一点)的方式。当你的错误出现,它触发这个事件,你的WinForms应用程序将被通报。这就是所谓的双面打印合同:

What you can do is have the windows service have way of registering for an event (you can do this through using Windows Communication Foundation). When your error comes up, it fires that event, and your winforms app will be notified. It's called a duplex contract:

<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/0eb69998-0388-4731-913e-fb205528d374/\">http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/0eb69998-0388-4731-913e-fb205528d374/

<一个href=\"http://msdn.microsoft.com/en-us/library/ms731184.aspx\">http://msdn.microsoft.com/en-us/library/ms731184.aspx

其实真的很酷的事情是,你可以有多个应用程序听了这样了。所以,你可以在屏幕上显示出来,并有其他应用程序日志等它没有两个外部的应用程序知道对方什么。

Actually the really cool thing is that you can have multiple applications listening this way too. So you can display it on screen, and have another application log it etc. without the two external apps knowing anything about each other.

这篇关于C#:GUI显示来自Windows服务的实时信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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