Objects raising events after "reinstantiation"

F

franzpaniero

I've run into this problem a couple of times when creating objects that raise
events but I've always been able to code around it so I never asked the
question. I'm using a Process object with .EnableRaisingEvents turned ON and
..BeginOutputReadLine() so that I can process the output as it is generated
from my process.

The scenario for use is that this executable uses an .ini file that contains
some settings with one of them being a path to an input file that will be
scrubbed. This executable has a known issue in that only 1000 or so entries
can be processed reliably during one "run" otherwise strange results occur if
there are more. My use case provides that I will often have cases where I
need to process 1000+ entries so my plan was to split however many entries
into files of 1000 lines each and the whenever the Process.Exited event is
fired when the executable finishes running, I would modify the .ini file to
point to one of the other input files, re-start the process however many
times I need to in order to process all my input.

The problem lies in that after the first run, the Process does not raise
events anymore for .OutputDataReceived but I am not re-instantiating the
Process object in my class so I'm not sure why I cannot continue to capture
events when I am in essence just re-starting the process with all the same
properties turned on.

FYI I do not have the code for this picky executable program either so
please do not give any lame answers in that vein...I'm interested in how
events are raised when objects die out and are re-instantiated or the context
I've described above. Also I am calling Process.CancelOutputRead() in the
Exited event and then calling Process.BeginOutputReadLine() after I re-start
it so I don't believe this is the problem either.

Thanks in advance.
 
F

franzpaniero

I found the solution to this after doing a little more digging. I've always
used WithEvents and the Handles tag in my function declarations and I never
realized how much less flexible that is than using AddHandler. AddHandler
resolved this beautifully.
 

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