Event not raising if it's fired within constructor?

  • Thread starter Thread starter Özden Irmak
  • Start date Start date
Ö

Özden Irmak

Hello,

I only have a simple question...If an event is fired in the contractor of a
class, it seeems that it isn't raised?

Is this a normal behaviour?

Regards,

Ozden
 
Özden, yes this is normal behaviour. An instance of the class hasn't been
created yet and you therefore you can't and don't have a handler to trap any
event you attempt to raise.

But just out of interest what is your reason for wanting to do this anyway?

Regards
Hexathioorthooxalate.
 
Hello,

This class (Derives from Panel) creates a form with a listbox kind control
in it and this event asks confirmation when a new item to this listbox is
added...And as this item addition is done in the constructor it doesn't fire
this event...

Anyway, I just wanted to be sure whether this is a normal behaviour or
not...I'll do the item addition somewhere else it seems...

Thanks for your help...And happy new year by the way!:)

Regards,

Ozden
 
Özden Irmak said:
I only have a simple question...If an event is fired in the contractor of a
class, it seeems that it isn't raised?

Is this a normal behaviour?

Yes. The object isn't "born" until all constructors finish.
 
* "Özden Irmak said:
I only have a simple question...If an event is fired in the contractor of a
class, it seeems that it isn't raised?

Event handlers are not added yet at the moment when raising the event
from the ctor. That's why it seems that the event doesn't get raised.
 
Back
Top