Reputation: 10758
I have a strange application in that for development and testing I need a windows forms application so that I can monitor what it is doing. For production, the application will be started from a service and no visible UI is needed. I dont really want to re-write the app. once it is completed into a console app so I would like to leave it as it but start it from the service.
My question is will this application work fine from a service? At the moment it has UI elements and I have been able to successfully start the application from a service using the Process class (System.Diagnostics).
Could anything go wrong with this approach?
Upvotes: 0
Views: 1075
Reputation: 9986
You will need to tweak the value of Type
field in registry SYSTEM\CurrentControlSet\Services\YourServiceName
registry location. See this article.
Just as a side note; services aren't meant to work like that - they're meant to be entirely in the background.
Better would be to expose some sort of external control API, probably over network sockets for instance. And then you can have a separate windows forms app running in the system tray or in Hide
mode and pops up every time the it receives something from the service.
Upvotes: 0
Reputation: 2863
Use the configuration manager to create a gui build and a service build for your application and then use the following structure to control the way your application starts:
#ifdef GUI
// load gui
#else
// run as service
#endif
Upvotes: 2
Reputation: 33857
If your logic is in a seperate library and your GUI application is just calling to this, then it should be trivial to also have a console application doing the same thing. You only change your logic in one place, and have two front ends...
Upvotes: 0
Reputation: 15571
I think there is no issue.
If the application is a console app, you could have controlled the visibility using a configuration only. Now, you need to have another application (Winform) to do the same thing.
Upvotes: 1
Reputation: 27384
I think generally the way this is usually done is to have a separate GUI application that communicates to the service in some way.
Upvotes: 1