如何在C#中使用Windows服务? [英] How to use a windows service in C#?

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

问题描述

嗨大师,



我想创建一个在系统启动时自动在后台运行的Windows服务。

我可以做到好吧,现在我想从我的应用程序中调用一个函数,例如点击一个按钮。并且该函数从正在运行的服务向我的应用程序返回一些内容。



我在互联网上查找并找到了一些关于创建Windows服务,构建安装程序和注册服务;但是,我似乎找不到任何关于如何通过不同的应用程序与运行服务进行交互的文档。



现在我该怎么做?



谢谢。

解决方案

嗨..



请访问这个链接。



http://www.aspdotnet-suresh.com/2011/06/creating-windows-service-in-c-or.html [ ^ ]


这不是Windows服务的工作方式。 Windows服务基本上是一个在后台静默运行(和无UI)以执行某些任务的程序。你不能与之交互(好吧,你可能会这样,但它并不意味着那样工作)。



你在想什么是网络托管在Web服务器上的服务,为您提供来自给定数据存储(通常是数据库)的数据。



您想要什么返回到您的应用程序?



如果它是关于本地系统的一些信息,那么当你的程序本身可以检索信息时,为什么还需要一个服务?



如果是您需要退回的远程信息,您将需要创建一个Web服务并远程托管它...



如果我可以给你一个未来问题的提示:你的键盘有一个CAPS按钮。用它!在所有小写中写一个文字是草率和不尊重。至少将句子中的第一个字母和I大写。 [/编辑]

Hi masters,

I want to create a windows service that run in background automatically when system boot.
I can do it well, now I want to call a function in my service from my app when for example a button clicked. And that function returns something to my app from the running service.

I have looked on the Internet and found a few examples about creating a Windows Service, building installers, and registering the service; however, I cannot seem to find any documentation on how to interact with running services via a different application.

Now how do I do this?

Thanks.

解决方案

Hi..

please visit this link.

http://www.aspdotnet-suresh.com/2011/06/creating-windows-service-in-c-or.html[^]


That's not the way a windows service works. A windows service is basically a program that runs silently (and UI-less) in the background to perform certain tasks. You can't interact with it (well, you might be able to, but it's not meant to work that way).

What you are thinking of is a web service that is hosted on a web server and provides you with data from a given data storage (typically a database).

What do you want to return to your app?

If it is some information about the local system, then why do you need a service for it when your program just as well can retrieve the information itself?

And if it is remote information you need to return, you will want to create a web service and host it remotely...

[EDIT] If I can give you a tip for future questions: Your keyboard has a CAPS button. Use it! Writing a text in all lower case is sloppy and disrespectful. At least capitalize the first letter in the sentence and "I" of course. [/EDIT]


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

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