Raise events in a class.new statement dows not fire???

P

Peter van der Veen

Hi

I have a class with an error event.

When i initialize the class from a program the events in the class new
sub does not fire. (i don't get them back)
When calling anonther sub in the same class the events fires without
problems.

How can i get the events raised in the class new sub?
Or is it not possible.

Peter
 
M

Mattias Sjögren

Peter,

You can raise it, but there can't be any event handlers registered for
the event at that point, so it's kinda pointless.

What kind of event do you need to raise from the constructor? You
could possibly pass a delegate to the constructor and use that to
notify the handler.



Mattias
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Peter,

This is not possible. While a class instance is being constructed, the
subscribers haven't had a chance to subscribe to the instance events yet as
instance construction is still in progress.
 
H

Herfried K. Wagner [MVP]

* Peter van der Veen said:
I have a class with an error event.

When i initialize the class from a program the events in the class new
sub does not fire. (i don't get them back)

That's because the instance of the class isn't completely constructed
and no handlers are registered at that time.
 
P

Peter van der Veen

Thx

So i have to port the code in the new constructor to a new sub and
call it afterwards.

Peter
 

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