472,954 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 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 5325

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: SP | last post by:
Please advice. I am not familiar with the concepts of windows service. I am trying to access a xml configuration file from windows service. But it is failing. configuration file is in the same...
6
by: Dean R. Henderson | last post by:
I have a DTS Package I am able to execute successfully from a Windows Form application, but I cannot get this to work from an ASP.NET Web Service, although the Web Service impersonates the same...
5
by: Brian Patrick | last post by:
I have an application model which will consist of a front-end configuration application, which needs to control the state of a back-end vb.net windows service (which is the component that does all...
2
by: Trevor | last post by:
Argh! This problem is driving me nuts! Can you help? In November of 2003, I installed a web service on Windows Server 2003 built in VB.NET for v1.1.4322 of the framework. It contains a timer...
4
by: PeterW | last post by:
I have a Windows service that needs to get some values from a config file. I place the config file for the service in the System32 directory. I do not get the values using the usual...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
2
by: Olegus | last post by:
I have Windows service MyService, that reads some settings from MyService.exe.config file via ConfigurationManager.AppSettings. I tried to write small WinForm frontend app(called it Manager.exe)...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
1
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service that I want to host in windows service. The problem is that if I host it as windows service it does not use the configuration file. I have to define the binding,...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.