This is a migrated thread and some comments may be shown as answers.

Use WPF data to configure Windows Service

0 Answers 78 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joel Palmer
Top achievements
Rank 2
Joel Palmer asked on 16 Jun 2011, 03:56 PM
I have a Windows Service that needs a significant amount of user input.  Yes, I can put those values in the app.config file but then that seems lazy. This UI includes the ability to configure the service, start/stop the service and a log viewer.  So, I'd like the Windows Service to pick up the values entered by the UI.  Does anyone have a "standard" or "best practices" way of doing this?  Or, even just a better idea than my own.

My current approach:
The UI's data context is an object that contains all of my UI entries.  Serialize the object as XML using XmlSerializer.  Then whenever the Windows Service cycles, go to this XML file and deserialize it.  Then, use that object in the Windows Service.
  • My question on this approach is... what is the best way to tell the Windows Service where the UI was installed?  I don't want to hard code this because the installer could put it it on the D:\ or who knows where?  Once again, I think making the user enter this value in the app.config is a lazy approach on the developer front.  Ideas:
    • I attempted to use the Process of the UI to find the Environment.CurrentDirectory of the UI process but that doesn't seem to exist.  Remember, the UI starts/stops the service so I know the UI will be opened when the service first starts.  Anyone have ideas on this front?
    • When the UI is installed or starts the first time, I could save the directory to a registry setting... but that seems pretty old school.  Is there a better way to do this?

 

Any suggestions are appreciated. 

Thanks,
Joel

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Joel Palmer
Top achievements
Rank 2
Share this question
or