Passing EventHandler

  • Thread starter Thread starter Csharp Dummy
  • Start date Start date
C

Csharp Dummy

Hi,

I have a list of objects each with their own timer object and would
like them to use the same event handler function:
protected virtual void Generator_EventHandler(object Sender,
ElapsedEventArgs E)
{
// do something
}
For some reason I have problems passing the eventhandler to the
objects using the constructor.

Does anyone know how that works?
 
Show the code.

An EventHandler is just a regular delegate type, and you can create an
instance of it and pass the reference to that instance to whatever
method you want, including a constructor, as long as the method has a
parameter taking that type or a type compatible with it (base type or
convertible, for example).  It works like any other type.

It's as simple as that.

So, unless you post the code you tried, with an explanation of what you
expected it to do, and what it did instead, including the exact text of
any error messages you may have gotten, it's not possible to know what
you're asking.  And it's not worth the effort to make guesses about what
you might be asking.

Pete

Pete,

Thank you that was it - I didn't create an instance.
Works now.
 
Back
Top