views:

74

answers:

5

Hi, 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?

+1  A: 

I think generally the way this is usually done is to have a separate GUI application that communicates to the service in some way.

Chris
Hi Chris, yes I agree however in this case you can imagine the application like a file copy or something. Once in production it wont need any monitoring - just fire and forget. But in dev. I want to for example see which files are getting copies in the UI (thats just an example really).
RemotecUk
+1  A: 

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.

Kangkan
A: 

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...

Paddy
+2  A: 

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
Phil
That's what I usually do as well in such a situation. Note that it doesn't really matters anyway: unless you start poping up modal dialogs in your service (in which case the user might get notified under R2/7) you can happily create and run your windows forms from within your service context. Not creating the form if running in the context of a service is just a small resource saving step.
Stephane
A: 

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.

KMan