ctrlfreak
ctrlfreak

Reputation: 1

how to use timer with wcf

I have implemented this example with no luck so far,

public class WCFService : System.Timers.Timer, IWCFService
{
    public WCFService()
    {
        base.Interval = 10000;
        this.Enabled = true;  
        this.Elapsed += new
        System.Timers.ElapsedEventHandler(WCFService_Elapsed);
    }

    void WCFService_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {   
       //Do Checking
    }

WCFService_Elapsed is supposed to be called after 10000ms but during debuging it's now working. Any thoughts?

I'm trying to self-check some variables and send an email under some circuimstances.

Upvotes: 0

Views: 4503

Answers (2)

ctrlfreak
ctrlfreak

Reputation: 1

I changed my code to:

public class WCFService : IWCFService
{
  public WCFService()
  {        
    System.Timers.Timer timer = new System.Timers.Timer();
    timer.Elapsed += new System.Timers.ElapsedEventHandler(WCFService_Elapsed);
    timer.Interval = 1000;
    timer.Enabled = true;         
    timer.Start();
  }

void WCFService_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{   
   //Do Checking
}

This does work but I have to invoke at least once a method from the service to start the timer.

Upvotes: 0

uk2k05
uk2k05

Reputation: 388

Does specifying your elapsed event BEFORE enabling the timer make any difference? I would have added this as a comment if I had the rep.

Upvotes: 1

Related Questions