I'm writing a C# service and its main function is to pull photos from a database and save them to a directory twice a day. This operation takes about 15 minutes typically (there are a lot of photos). If I put the logic to run the program in OnStart(), then after a minute or so of starting up the service reports that it did not start up successfully. This is because it is in the OnStart() method for too long.
How can I set a timer in the OnStart() method that will call my RunApp() method after about a minute?
Edit: Here is some code. After setting up the scheduler that makes it run daily, I also want to just plain run it. I figured setting a timer for about a minute would work, that way it has time to get out of the OnStart() method. Then when the timer goes off the app will run.
protected override void OnStart(string[] args)
{
Scheduler sch = new Scheduler("Photo Sync");
try
{
MailConfiguration mailConfig = new MailConfiguration(Properties.Settings.Default.EmailLogTo, Properties.Settings.Default.EmailLogFrom,
"Photo Sync Photo Service error", Properties.Settings.Default.SmtpServerIp, "Photo Sync");
sch.MailComponent = mailConfig;
}
catch
{
}
sch.SchedulerFired += new EventHandler(RunApp);
try
{
sch.ScheduleDaily(Properties.Settings.Default.DailyScheduledTime);
}
RunApp();
}