Events

G

Guest

Hi
I'm aware of two different ways of raising events from a class, using an EventHandler and deriving a class from this in order to pass information - and using a delegate.

I'm fine with either of these, but what I'd essentially like to do is when I type += on the event handler, and it says in the intellisense 'Press tab to insert event handler' etc., for it to come up with the correct derived event args class, not just the basic 'EventArgs', as it does currently. It does this for the framework events. Is this because they've got delegates other than EventHandler?

I've heard that delegates other than EventHandler are slower than deriving a class from EventArgs, is this right?
 
J

Jon Skeet [C# MVP]

Patty O'Dors said:
I'm aware of two different ways of raising events from a class, using
an EventHandler and deriving a class from this in order to pass
information - and using a delegate.

No, both of these are using delegates. EventHandler *is* a delegate.
I'm fine with either of these, but what I'd essentially like to do is
when I type += on the event handler, and it says in the intellisense
'Press tab to insert event handler' etc., for it to come up with the
correct derived event args class, not just the basic 'EventArgs', as
it does currently. It does this for the framework events. Is this
because they've got delegates other than EventHandler?

Yes. EventHandler is specified to take two parameters, of type object
and EventArgs respectively. If you want a different signature, you need
to use a different delegate.
I've heard that delegates other than EventHandler are slower than
deriving a class from EventArgs, is this right?

They're invoked slightly slower in Windows Forms, yes. I don't know how
much difference there is though.
 
G

Guest

OK thanks.


Jon Skeet said:
No, both of these are using delegates. EventHandler *is* a delegate.


Yes. EventHandler is specified to take two parameters, of type object
and EventArgs respectively. If you want a different signature, you need
to use a different delegate.


They're invoked slightly slower in Windows Forms, yes. I don't know how
much difference there is though.
 

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