Compile error on TimerCallback

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()
{
}
}
 
B

Barry Kelly

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top