Compile error on TimerCallback

  • Thread starter Thread starter Thirsty Traveler
  • Start date Start date
T

Thirsty Traveler

I am getting a compile error ("No overload for 'Timer_Tick' matches delegate
'System.Threading.TimerCallback'") on the following code and can't figure
out why. Does anyone have any ideas?

public partial class CrystalService : ServiceBase
{
public CrystalService()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
TimerCallback tcb = new TimerCallback(this.Timer_Tick);
Timer timer = new Timer(tcb);
}

protected override void OnStop()
{
}

public void Timer_Tick()
{
}
}
 
Thirsty Traveler said:
I am getting a compile error ("No overload for 'Timer_Tick' matches delegate
'System.Threading.TimerCallback'") on the following code and can't figure
out why. Does anyone have any ideas?
TimerCallback tcb = new TimerCallback(this.Timer_Tick);
public void Timer_Tick()

Timer_Tick must match the declaration for the TimerCallback delegate:

public delegate void TimerCallback(Object state)

That means you must modify your Timer_Tick method to receive an object
parameter:

public void Timer_Tick(object state)

-- Barry
 
Back
Top