2

Is it possible to write a background function in a master page that triggers after a specific period of time, say 5 hours?

function()    
{

    execute code from the clsGeneral Class

}

Please suggest how this can be implemented.

Jeremy McGee
  • 24,842
  • 10
  • 63
  • 95
abhishek mehra
  • 119
  • 2
  • 7

1 Answers1

1

Pre IIS 7.5 you don't. (technically you can, but it's stupid). IIS is free to terminate your app whenever he wants, and when IIS is restarted, apps are restarted "lazily" (until someone opens a page of your web app, the web app isn't started).

From IIS 7.5 onward you could using the Application Warm-Up Module (sadly the beta was removed :-) ). With it you create a Thread that waits the specified time and does something. Quite easy.

The "right" solution is normally to create a Windows Service and use Quartz. Read here for example Scheduler for ASP.NET?

Community
  • 1
  • 1
xanatos
  • 109,618
  • 12
  • 197
  • 280
  • Well, you don't _need_ to use Quartz; rather, a simple Windows service is (generally) all you need together with a simple `Timer`. However, Quartz can be a neater solution, yes. – Jeremy McGee Oct 02 '11 at 12:07
  • 1
    @JeremyMcGee As you said :-) But in the end, if you need to do it, it's better you do it correctly. Without quartz if your machine is rebooted you'll probably lose/delay a trigger (unless you write code to compensate for it). With quartz, this extra necessary code is already included in the library. – xanatos Oct 02 '11 at 12:12