By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,214 Members | 1,964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,214 IT Pros & Developers. It's quick & easy.

Problems starting a scheduler from Application_Start()

P: n/a
Hi,

While I realise that this may not be a very nice solution architecturally, I
kick off a Scheduler in an ASP.NET 2.0 webservice in Application_Start()
which is supposed to call a stored proc in a database once a day every day.

The code works on the day that the webservice is deployed, but not on
subsequent days unless I restart IIS.

The code looks like this:

void Application_Start(object sender, EventArgs e)
{

Scheduler sch = new Scheduler();

}

public Scheduler()
{
Logger.Write("Initialising scheduler.... " + DateTime.Now,
"ABSPerformance");
System.Timers.Timer testTimer = new System.Timers.Timer();
testTimer.Enabled = true;
testTimer.Interval = 60 * 1000;

testTimer.Elapsed += new
System.Timers.ElapsedEventHandler(testTimer_Elapse d);

}

private void testTimer_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
if (!DateTime.Now.DayOfWeek.Equals(DayOfWeek.Saturday ) &&
!DateTime.Now.DayOfWeek.Equals(DayOfWeek.Sunday))
{

if (DateTime.Now.Hour.Equals(8) &&
DateTime.Now.Minute.Equals(30))
{
ABSData.executeNonQuery("StructuredCD.sp_ABS_Updat e",
null);
}

}

}

Is there a technical reason why I can't use the scheduler in this way, why
it only works on the first day?

As you have probably guessed, I am new to ASP.NET, so any help would be
appreciated.

Many thanks

Rob


Feb 25 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"austirob" <au******@discussions.microsoft.comwrote in message
news:81**********************************@microsof t.com...
Hi,

While I realise that this may not be a very nice solution architecturally,
I
kick off a Scheduler in an ASP.NET 2.0 webservice in Application_Start()
which is supposed to call a stored proc in a database once a day every
day.
You should probably let the database execute the stored proc once a day.
Alternatively, write a small console app to run it, and use the Windows Task
Scheduler to cause it to run periodically. This usage has nothing to do with
web services, which are not meant for anything like this!

I wouldn't be surprised to see your sch and testTimer objects being garbage
collected.
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer
Feb 25 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.