Help with a timer error

Hello all,

I have the following code that should work. But it gives an error on compile. Any ideas would be really appreciated!

Thanks,
Tim

Type mismatch error.  Expected delegate Delegate( Timer ), but got delegate Delegate( Timer ) as Boolean

Code

Private Property tmrChkDownload As Timer
Private Function tmrCheckForDownload(tmrChkDownload As Timer) As Boolean

In the Function declaration, I want a return boolean value. That’s the only thing I see as being off..

//---- Instantiate tmrChkDownload ----//
tmrChkDownload = New Timer
AddHandler tmrChkDownload.action, AddressOf tmrCheckForDownload
tmrChkDownload.RunMode = timer.RunModes.Off
tmrChkDownload.Period = 30000 
tmrChkDownload.Enabled = False
tmrChkDownload.Reset

Actually, if I just remove the return data type - Boolean - it compiles fine. I do not understand what the problem is…

Tim

A Delegate is a method signature - the parameters and return values. If you want to use a method as a Delegate, the signature of the method must match the signature of the Delegate. In this case, your method tries to return a Boolean, but the Timer Delegate does not specify a return value. Removing the Boolean thus makes your method usable as a Timer Delegate.

1 Like

This doesn’t mean that you can’t do what you want through. If you subclass WebTimer (and I really suggest you do for predictable results), you can implement the Action event and then create your own Action event definition that accepts a Boolean return value. Then you just call that method from the original event and do what you want with the Boolean return value.

Just keep in mind that you’ll get False if the custom event isn’t handled.

One big thing I messed up with, was putting this in the Targets-> web. This is actually a console app.

I suppose tho that I could still do what Greg suggests.
Thanks guys!
Tim