locked
Scheduling a method or WS call RRS feed

  • Question

  • User-1014877033 posted

    I have an ASP.NET application that requires certain code to fire on a periodic basis.  i.e. An image clean-up routine needs to fire every 5 minutes.  An hourly email process needs to fire.  A daily cleanup needs to fire.

    What is the best way to schedule this type of logic? 

    I am flexible where the code resides (in a WS, in an ASPX page, ASHX, etc.)

    The Task Scheduler seems to work only with starting applications, and not with calling a WS.

    Any help or ideas is appreciated.

     

    thanks

    Saturday, December 5, 2009 10:50 PM

Answers

  • User-1179452826 posted

    Use the scheduler to schedule a cosole app to be run. Within the console app, call the service.

    WebRequest req = WebRequest.Create("sevice url");

    WebResponse res = req.GetResponse(); 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 6, 2009 12:23 AM

All replies

  • User-1179452826 posted

    Use the scheduler to schedule a cosole app to be run. Within the console app, call the service.

    WebRequest req = WebRequest.Create("sevice url");

    WebResponse res = req.GetResponse(); 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 6, 2009 12:23 AM
  • User-952121411 posted

    Here is what you need to complete your solution; you can accomplish this entire task using a Windows Service.  You could use polling with a Timer or something of the similar to execute the process on an interval, but I do not recommend it regardless of the type (System.Timers.Timer, System.Threading.Timer, etc,) due to thread issues that could arise.

    I have implemented a Windows Service within the last few months that does exactly what you are inquiring about; run a periodic process on a set time interval.  A nice method IMO is to use a 'RegisterWaitForSingleObject' method from the System.Threading namespace.

    As defined in the MSDN:  "Registers a delegate to wait for a WaitHandle, specifying a 32-bit signed integer for the time-out in milliseconds."

    This method is well laid out with code examples in the following Blog entry by Mebyon Kernow:

    http://blogs.msdn.com/morgan/archive/2008/12/18/periodic-execution-in-net.aspx

    Here is the MSDN Documentation:

    http://msdn.microsoft.com/en-us/library/w9f75h7a.aspx

    In your case you could easily have multiple delegates registered with there own timeout value as you needed, each running their own process.  The process can do anything you need from the Windows Service:  call a local method, a .dll, WCF service, .asmx service, etc.

    ...and lastly, you might be saying "I don't know how to create and use a Windows Service in .NET!".  Well to get you going on that (there are quite easy by the way to get up and running), check out the following site:

    Walkthrough: Creating a Windows Service Application in the Component Designer:

    http://msdn.microsoft.com/en-us/library/zt39148a.aspx

    Running a Periodic Process in .NET using a Windows Service: 

    http://allen-conway-dotnet.blogspot.com/2009/12/running-periodic-process-in-net-using.html

    That should be everything you need, hope this helps! Smile

    Wednesday, December 9, 2009 4:38 PM
  • User-1067358373 posted

    Check this out.

    http://kodethoughts.blogspot.com/2009/06/creating-windows-task-scheduler-service.html


    Thursday, December 24, 2009 12:31 PM