Threading.Timer invokes asynchronously many methods

Posted by Dimitar on Stack Overflow See other posts from Stack Overflow or by Dimitar
Published on 2009-11-29T13:40:05Z Indexed on 2010/06/16 1:02 UTC
Read the original article Hit count: 291

Filed under:
|
|
|
|

Hi guys! Please help! I call a threading.timer from global.asax which invokes many methods each of which gets data from different services and writes it to files. My question is how do i make the methods to be invoked on a regular basis let's say 5 mins?

What i do is: in Global.asax I declare a timer

protected void Application_Start()
{
    TimerCallback timerDelegate = new TimerCallback(myMainMethod);
    Timer mytimer = new Timer(timerDelegate, null, 0, 300000);
    Application.Add("timer", mytimer);
}

the declaration of myMainMethod looks like this:

public static void myMainMethod(object obj)
{
    MyDelegateType d1 = new MyDelegateType(getandwriteServiceData1);
    d1.BeginInvoke(null, null);
    MyDelegateType d2 = new MyDelegateType(getandwriteServiceData2);
    d2.BeginInvoke(null, null);
 }

this approach works fine but it invokes myMainMethod every 5 mins. What I need is the method to be invoked 5 mins after all the data is retreaved and written to files on the server.

How do I do that?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about asynchronous