I have a windows application built by c# and I need to run it every now and then, so I would like to create 开发者_运维问答it as a windows service. How is it possible to create the windows service from the existing soluion?
Maybe it's easier for you to call it as a Scheduled Task, that way you won't need extra coding.
You could use the SrvAny tool to run your existing application as a service.
Ah, this depends on how you coded your application :) Generally, if I am writing a class that is "service-like" (e.g, it starts, stops, and can be paused), I will write it just like that. I can instantiate this class anywhere I wish.
This makes it very easy when it comes time to turn it in to a real windows service as I simply create the windows service using Visual Studio, and drop my class in, mapping Start/Stop handlers to my calls.
I've found this approach over the years, in both C++ and C# to save a lot of ball-ache with services. It does, for example, make it trivial to place the class in a console-application and test it without having to start and stop through the services interface.
精彩评论