0

I have this code:

class ServiceConsumer
{
    static void Main(string[] args)
    {
         //call from here retriveEvents method evry 5 minutes!
    }


    private static void retriveEvents()
    {

        IContract proxy = ChannelFactory<IContract>.CreateChannel(new BasicHttpBinding(),
                                        new EndpointAddress("http://someAddress/Hydrant.svc"));

        using (proxy as IDisposable)
        {
            var rows = proxy.GetData(new DateTime(2000, 5, 1));
        }
    }
}

The retriveEvents() method is creating proxy and retrieve data from host service. How can I call asyncroniusly retriveEvents() method to access host service evry 5 minutes?

Michael
  • 13,950
  • 57
  • 145
  • 288

2 Answers2

0
static void Main(string[] args)
{
   System.Timers.Timer aTimer = new System.Timers.Timer();
   aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
   aTimer.Interval=360000;
   aTimer.Enabled=true;

   while(true) { }
}

private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
     // Do your stuff
     retriveEvents();
}
wake-0
  • 3,918
  • 5
  • 28
  • 45
0
var timer = new System.Threading.Timer((e) =>
{
    MyMethod();
}, null, 0, TimeSpan.FromMinutes(5).TotalMilliseconds);
Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62