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

Custom EventHandler and Windows Forms

P: n/a
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,

--
John Bowman
Verona, WI
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Nov 21 '05 #2

P: n/a
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
"steve" <a@b.com> wrote in message news:10************@corp.supernews.com...
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

Nov 21 '05 #3

P: n/a

"John Bowman" <jm******@charter.net> wrote
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
Nov 21 '05 #4

P: n/a
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

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...

"John Bowman" <jm******@charter.net> wrote
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

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.