我有一個簡單的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#控制檯應用程序作爲Windows服務運行
- 2. c#應用程序作爲服務運行有什麼優勢?
- 3. 如何在windows上運行grails應用程序作爲服務
- 4. 如何運行Windows GUI應用程序作爲服務?
- 5. 我該如何運行我的Java應用程序作爲窗口服務?
- 6. 如何使用WinRun4J作爲Windows服務運行Java應用程序
- 7. 如何使用AutoIt控制作爲Windows服務運行的UI應用程序?
- 8. 如何從Cocoa應用程序運行Automator工作流/服務?
- 9. 如何運行通過在C#服務應用程序的GUI應用程序
- 10. 如何查看Windows窗體應用程序在Windows服務應用程序作爲服務運行
- 11. 我作爲服務運行
- 12. 如何編寫我也可以作爲winforms程序運行的c#服務?
- 13. 打印作爲Windows服務運行的腳本/應用程序
- 14. 運行.NET程序作爲服務
- 15. 作爲Web應用程序在Web服務器上運行Java應用程序?
- 16. 如何爲Web應用程序運行Node.JS服務器?
- 17. 如何使用C#從Windows服務運行EXE程序?
- 18. 如何將Play Framework 2.4.4應用程序作爲Windows服務運行?
- 19. Android:我的應用程序未使用時運行服務
- 20. 在Windows上運行Java獨立應用程序(作爲服務)
- 21. 在Android上運行Phonegap應用程序作爲服務
- 22. iOS:在後臺運行應用程序作爲服務
- 23. 在iOS/Cydia上運行應用程序「作爲服務」
- 24. 作爲Windows服務運行應用程序
- 25. 將Java應用程序作爲服務運行
- 26. 運行的應用程序作爲服務於Android
- 27. JFileChooser應用程序作爲服務運行
- 28. 運行OpenJMS服務器作爲嵌入式應用程序
- 29. 將Windows應用程序作爲服務運行?
- 30. 作爲Windows服務運行Java應用程序
可能重複[使用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