By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

raising events

P: n/a
Hi All,

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

Marcel
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Marcel van der Gragt" <marcelASTvandergragtDTnl> wrote in message
news:e4**************@TK2MSFTNGP10.phx.gbl...
.. . .
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.
Nov 20 '05 #2

P: n/a
What about static events?

=)

"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:bu**********@yarrow.open.ac.uk...
"Marcel van der Gragt" <marcelASTvandergragtDTnl> wrote in message
news:e4**************@TK2MSFTNGP10.phx.gbl...
. . .
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.

Nov 20 '05 #3

P: n/a
"Marcel van der Gragt" <marcelASTvandergragtDTnl> schrieb

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.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #4

P: n/a
* "Armin Zingler" <az*******@freenet.de> scripsit:
I'm I correct that you cannot raise events in the New (or
constructor) procedure?


Yes. There are no handlers added at this time.

<http://www.google.de/groups?q=dotnet+vb+constructor+raise+event&ie=UTF-8&scoring=d>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.