Thanks Andy. I got the configurable timer interval service to work !
I followed your advise and that of Peter in a later post. I moved all
the code to the onstart and made the timer and interval static at the class
level
I used MessageBoxes throughout the OnStart try block as needed to find out
which lines of code were working and which weren't.
That is how I discovered I needed to make the timer a static at the class
level because it was erroring out saying the object hadn't been created, ie.
the timer.
Then I deleted those but kept the messagebox in the catch block for the
moment.
Relevant code is below.
Thanks again. -Greg
public class Service1 : System.ServiceProcess.ServiceBase
{
static public System.Timers.Timer timer1;
static double interval;
***code **
protected override void OnStart(string[] args)
{
try
{
System.Timers.Timer timer1 = new System.Timers.Timer();
timer1.Elapsed += new
System.Timers.ElapsedEventHandler(timer1_Elapsed);
interval =
Convert.ToDouble(System.Configuration.Configuratio nSettings.AppSettings["interval"]);
timer1.Interval = interval;
timer1.Enabled = true;
}
catch(Exception ex)
{
MessageBox.Show("In OnStart Component" + ex.ToString());
}
"Andy" <aj*****@alum.rit.edu> wrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Well, do what it says, and move the code out of the
InitializeComponent.
I suggest you move it into the OnStart handler.
Also, doing your Convert should be wrapped in a Try Catch incase the
value doesn't exist or isn't a double number; in your catch, you can
throw the exception, or set a default interval value (and log a
warning).
HTH
Andy
hazz wrote: Error: The designer cannot process the code at line 56:
interval =
Convert.ToDouble(System.Configuration.Configuratio nSettings.AppSettings["interval"]);
The code within the method 'InitializeComponent' is generated by the
designer and should not be manually modified. Please remove any changes
and
try opening the designer again.
hmmmm