Link to home
Start Free TrialLog in
Avatar of MSAIT
MSAIT

asked on

Adding a timer to my C# Console app

Hi all,

I urgently need to add a timer to my Console app. I want my routine(Get_XML_Data) to run every 5 mins

thanks
SOLUTION
Avatar of AlexNek
AlexNek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MSAIT
MSAIT

ASKER

Thanks guys,

I found this on the net

 1:  //  Timer02.cs - Displaying Date and Time
 2:  //      Using the Timer class.
 3:  //      Press Ctrl+C to end program.
 4:  //------------------------------------------
 5:  using System;
 6:  using System.Timers;
 7:
 8:  class myApp
 9:  {
10:    public static void Main()
11:    {
12:      Timer myTimer = new Timer();
13:      myTimer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent );
14:      myTimer.Interval = 1000;
15:      myTimer.Start();
16:
17:      while ( Console.Read() != 'q' )
18:      {
19:          ;    // do nothing...
20:      }
21:    }
22:
23:    public static void DisplayTimeEvent( object source, ElapsedEventArgs e )
24:    {
25:        Console.Write("\r{0}", DateTime.Now);
26:    }
27:  }