Problems starting a scheduler from Application_Start()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?YXVzdGlyb2I=?=

    #1

    Problems starting a scheduler from Application_Start()

    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_Sta rt()
    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_Sta rt(object sender, EventArgs e)
    {

    Scheduler sch = new Scheduler();

    }

    public Scheduler()
    {
    Logger.Write("I nitialising scheduler.... " + DateTime.Now,
    "ABSPerformance ");
    System.Timers.T imer testTimer = new System.Timers.T imer();
    testTimer.Enabl ed = true;
    testTimer.Inter val = 60 * 1000;

    testTimer.Elaps ed += new
    System.Timers.E lapsedEventHand ler(testTimer_E lapsed);

    }



    private void testTimer_Elaps ed(object sender,
    System.Timers.E lapsedEventArgs e)
    {
    if (!DateTime.Now. DayOfWeek.Equal s(DayOfWeek.Sat urday) &&
    !DateTime.Now.D ayOfWeek.Equals (DayOfWeek.Sund ay))
    {

    if (DateTime.Now.H our.Equals(8) &&
    DateTime.Now.Mi nute.Equals(30) )
    {
    ABSData.execute NonQuery("Struc turedCD.sp_ABS_ Update",
    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






  • John Saunders [MVP]

    #2
    Re: Problems starting a scheduler from Application_Sta rt()

    "austirob" <austirob@discu ssions.microsof t.comwrote in message
    news:814BA38A-C1FB-4678-998F-8D4391AC4AB5@mi crosoft.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_Sta rt()
    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


    Comment

    Working...