raising events

  • Thread starter Marcel van der Gragt
  • Start date
M

Marcel van der Gragt

Hi All,

I'm I correct that you cannot raise events in the New (or constructor)
procedure?

Marcel
 
P

Phill. W

"Marcel van der Gragt" <marcelASTvandergragtDTnl> wrote in message
.. . .
I'm I correct that you cannot raise events in the New (or constructor)
procedure?

I believe so.
In order to catch an Event from an Object, you have to have a
reference to the object doing the Throwing. You won't have one
until the Object's constructor has completed.

HTH,
Phill W.
 
A

Armin Zingler

Marcel van der Gragt said:
I'm I correct that you cannot raise events in the New (or
constructor) procedure?

You can raise events in the constructor. The problem is that you have to
1. create the object
2. add event handlers

As "create the object" includes the execution of the constructor, the first
handler can not be added before the constructor has been executed completely.
Consequently, no event handler will be called when the event is raised in
the ctor.

One exception:
1. Pass a delegate to the constructor
2. In the ctor, add the delegate to the event
3. raise the event

But, it's easier to simply invoke the delegate.
 
C

CJ Taylor

What about static events?

=)

Phill. W said:
"Marcel van der Gragt" <marcelASTvandergragtDTnl> wrote in message
. . .

I believe so.
In order to catch an Event from an Object, you have to have a
reference to the object doing the Throwing. You won't have one
until the Object's constructor has completed.

HTH,
Phill W.
 

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