tags:

views:

54

answers:

2

My app uses a logging class which is invoked by each module as it is constructed.

The logging class fires an event every time a new entry is added, so that the GUI can be updated.

Is there any way I can listen to events fired during the construction of an instance?

For instance, I currently have this in my calling class:

input = new Inputs.Webcam();

input.log.LogUpdate += new LogUpdateHandler(...);

But I also write to the log during the construction of the modules. (Currently this throws an error because there isn't a listener.) Is there any way to listen to these events?

+2  A: 

This is completely impossible.

Instead, you can use a static event.

SLaks
I was afraid you'd say that. I think I'll refactor so that the log-entry-producing code is outside of the constructor.
Tom Wright
That's a very good idea.
SLaks
+2  A: 

Could not you just pass the log handler method to the ctor?

var input = new Inputs.Webcam(new LogUpdateHandler(...));
Bear Monkey