我有一个简单的c#应用程序需要作为服务运行。我如何使它作为服务运行而不是作为可执行文件运行?c# - 我如何使应用程序作为服务运行?
7
A
回答
2
Visual C# 2010 Recipies有一个例子,它会告诉你如何做到这一点,我试过使用VS 2008和.NET 3.5。
它相当于此:
- 在Visual Studio中的一个新的“Windows服务”应用
- 端口应用程序的源到服务的执行模型,AKA您的主要功能成为触发的事件处理程序的一部分由定时器对象或东西沿着这些线路
添加服务安装程序类,您的Windows服务项目 - 它会看起来像下面这段代码片段:
[RunInstaller(true)] public partial class PollingServiceInstaller : Installer { public PollingServiceInstaller() { //Instantiate and configure a ServiceProcessInstaller ServiceProcessInstaller PollingService = new ServiceProcessInstaller(); PollingService.Account = ServiceAccount.LocalSystem; //Instantiate and configure a ServiceInstaller ServiceInstaller PollingInstaller = new ServiceInstaller(); PollingInstaller.DisplayName = "SMMD Polling Service Beta"; PollingInstaller.ServiceName = "SMMD Polling Service Beta"; PollingInstaller.StartType = ServiceStartMode.Automatic; //Add both the service process installer and the service installer to the //Installers collection, which is inherited from the Installer base class. Installers.Add(PollingInstaller); Installers.Add(PollingService); } }
最后你会使用一个命令行工具来实际安装服务 - 你可以看到它是如何工作在这里:
让我知道如果您有任何问题。
3
在visual studio中有一个名为“Windows Service”的临时文件。如果您有任何问题要告诉我,我会整天写信。
+0
非常感谢乔纳森,我一定会带你 – 2010-07-12 20:23:28
2
有一个开源框架,它将.net应用程序作为Windows服务托管。没有安装痛苦,卸载Windows服务。它非常好地解耦。请检查这篇文章Topshelf Windows Service Framework Post
相关问题
- 1. c#应用程序作为服务运行有什么优势?
- 2. 将C#控制台应用程序作为Windows服务运行
- 3. 如何运行Windows GUI应用程序作为服务?
- 4. 我该如何运行我的Java应用程序作为窗口服务?
- 5. 如何使用WinRun4J作为Windows服务运行Java应用程序
- 6. 如何从Cocoa应用程序运行Automator工作流/服务?
- 7. 我作为服务运行
- 8. 如何编写我也可以作为winforms程序运行的c#服务?
- 9. 如何为Web应用程序运行Node.JS服务器?
- 10. 如何将Play Framework 2.4.4应用程序作为Windows服务运行?
- 11. 将Java应用程序作为服务运行
- 12. 将Windows应用程序作为服务运行?
- 13. Android RSS源解析和运行应用程序作为服务
- 14. 在Android上运行Phonegap应用程序作为服务
- 15. 在iOS/Cydia上运行应用程序“作为服务”
- 16. 在Windows上运行Java独立应用程序(作为服务)
- 17. 当应用程序作为服务运行时,AcceptSecurityContext失败
- 18. 运行WPF应用程序作为Windows服务
- 19. 作为Windows服务运行应用程序
- 20. 将应用程序作为服务运行的优点
- 21. iOS:在后台运行应用程序作为服务
- 22. Linux服务可以作为应用程序运行吗?
- 23. 将Java应用程序作为服务运行
- 24. Android:我的应用程序未使用时运行服务
- 25. 为Java应用程序创建安装程序作为Windows服务运行
- 26. 作为windows服务运行时应用程序的奇怪行为
- 27. 作为使用C#的Windows服务的Java应用程序
- 28. 使用C#类库作为COM +服务器应用程序
- 29. 如何设置作为Windows服务运行的Java应用程序的代理
- 30. Zuul服务器运行应用程序
可能重复[使用c#创建Windows服务的资源](http://stackoverflow.com/questions/1688382/resources-on-creating-a-windows-service-using-c) – Joe 2010-07-12 20:19:52
在这里,我已经找到了分步说明:https://stackoverflow.com/a/593803/7713750 – Rekshino 2017-10-10 07:47:13