471,071 Members | 1,205 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

Windows service with a configuration file

I wrote [my first] a windows service in c# (applause) and now I want to
add the ability to edit its settings. Basically this service checks an
email account at certain intervals and forwards the emails to another
email address. I want to be able to configure how often it runs (it
uses a timer, so setting the interval for that timer is what I mean by
that statement) and what account to check and what email address to
send to.

Seems easy, right? Well, I created a Settings.settings file and
populated it with all my variables (incomingPopServer,
incomingPopUsername, incomingPopPassword, etc...) that the service sets
onStart, but then I realized that I don't know how to get a form to
read & write these values.

I figured the way to do this is to create another VS.NET Project (the
service was called "Emailer Service" so this would be called "Emailer")
and create a single form with a few textboxes and a "Save" button that
saves those values to the Email Service's Settings.settings and then
restarts the service using the ServiceController class.

And here come my questions for you:

1) How do I get this Emailer project to "see" the settings from the
Emailer Service and how, once it sees them, do I get it to write to
them.
2) Is this even the best way to go about it? Might there be a
better/smarter/cheaper way of doing this?

Did that make any sense?

Thank you in advance,
Noah

Dec 13 '06 #1
1 4944

Yes you want a separate application. Typically a windows service with
a UI will have one app which is the windows service itself and a
totally separate app which is the UI. The service runs whether or not
the UI is running.

For your situation, you don't need the two apps to actually talk to
each other, they just need to share the same config file. Don't use
the Setings stuff--that's for preset application configuration and not
user configurable data. Instead use a custom file, most likely XML,
and put it in a standard location that both can find (suggest
Environment.SpecialFolders.CommonApplicationData as the root). You'll
want to have a dll that both apps share in common for reading/writing
the XML file in order to not have duplicated code.

When the UI changes the config file, you can use ServiceController to
restart the service from the UI app. Or you can use a
FileSystemWatcher in the service to watch the config file and
auto-reload when it changes (be sure to have a little delay to be sure
the UI is done writing changes before you reload).

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On 12 Dec 2006 18:22:51 -0800, no*************@gmail.com wrote:
>I wrote [my first] a windows service in c# (applause) and now I want to
add the ability to edit its settings. Basically this service checks an
email account at certain intervals and forwards the emails to another
email address. I want to be able to configure how often it runs (it
uses a timer, so setting the interval for that timer is what I mean by
that statement) and what account to check and what email address to
send to.

Seems easy, right? Well, I created a Settings.settings file and
populated it with all my variables (incomingPopServer,
incomingPopUsername, incomingPopPassword, etc...) that the service sets
onStart, but then I realized that I don't know how to get a form to
read & write these values.

I figured the way to do this is to create another VS.NET Project (the
service was called "Emailer Service" so this would be called "Emailer")
and create a single form with a few textboxes and a "Save" button that
saves those values to the Email Service's Settings.settings and then
restarts the service using the ServiceController class.

And here come my questions for you:

1) How do I get this Emailer project to "see" the settings from the
Emailer Service and how, once it sees them, do I get it to write to
them.
2) Is this even the best way to go about it? Might there be a
better/smarter/cheaper way of doing this?

Did that make any sense?

Thank you in advance,
Noah
Dec 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Trevor | last post: by
4 posts views Thread by PeterW | last post: by
4 posts views Thread by tshad | last post: by
2 posts views Thread by Olegus | last post: by
5 posts views Thread by dm3281 | last post: by
1 post views Thread by =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.