Custom EventHandler and Windows Forms

J

John Bowman

Hi All,

I'm hoping someone can help me out. I have a Windows Form dialog (call it
dialog1) that responds correctly to a custom event generated by another
class in my app. Inside this custom event handler that exists inside the
Windows Form object I need to load/display another Windows Form dialog, call
it dialog2. So, I dutifully instantiate Dialog2 and call it's ShowDialog()
method. Dialog2 happens to have a button on it that performs a utility
function which in turn instantiates and calls ShowDialog() on yet another
Windows Form...Dialog3. When Dialog 3 completes it's work, Dialog2 crashes
out, back to an exception handler way back in Dialog1 complainiing that an
External component threw an exception. This is highly reproducible... even
in a test app. Here's another weird part. If Dialog2 is directly
instantiated from a button on Dialog1, then the problem does not occur. I
tried calling Invoke from inside the custom event handler in Dialog1 to call
a delegate method to perform the work, but that makes no difference.

What gives? Any help would be appreciated.

TIA,
 
S

steve

doesn't sound like a mystery at all. simply, that the error occurs in
dialog3 and you aren't catching any from the dialog2 form. the error throws
you back to the last try/catch/on error statement defined (no matter what
point in code that may have been)...even to the point where nothing is
handled and your app crashes.

the easiest test for the theory is to place an on error resume next in the
interface that calls dialog3.showdialog().

hth,

steve
 
J

John Bowman

Steve,

Thanks for the reply. But this is NOT it. That code all works as expected
when we step through it. I think you missed my point that the problem does
NOT occur when the sequence is called directly rather than from the Custom
EventHandler.The error is produced by the system when Dialog2 finishes the
routine that instantiates Dialog3 and calls its ShowDialog(). There are NO
errors until you step past the End Sub in this routine in Dialog2. We have
it narrowed down to something related to calling this sequence from inside
the Custom EventHandler.

John
 
L

Larry Serflaten

John Bowman said:
Thanks for the reply. But this is NOT it. That code all works as expected
when we step through it. I think you missed my point that the problem does
NOT occur when the sequence is called directly rather than from the Custom
EventHandler.The error is produced by the system when Dialog2 finishes the
routine that instantiates Dialog3 and calls its ShowDialog(). There are NO
errors until you step past the End Sub in this routine in Dialog2. We have
it narrowed down to something related to calling this sequence from inside
the Custom EventHandler.

It would help if you posted the test app the just reproduces the error, so that
others can se the problem on their system....

LFS
 
J

John Bowman

Larry,

Thanks for the response. As I was cleaning up the test app so I could post
it, I found the problem. Basically, I discovered that the thread that Raises
the custom event & triggers the event handler, was using a
System.Windows.Forms.Timer from inside an object that was NOT a Form object
for some unknown reason. When this was changed to a proper
System.Timers.Timer object, all started working correctly.

John
 

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