Take the 2-minute tour ×
    Dim details As New frmDetails(ID, JobID, True)

The form flashes open and immediately closes. If I use Show() rather than ShowDialog() it stays open and look fine. Here are some things I've checked:

  • Breaking in FormClosing shows only

System.Windows.Forms.Form.OnFormClosing System.Windows.Forms.Form.CheckCloseDialog System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FContinueMessageLoop System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner System.Windows.Forms.Application.ThreadContext.RunMessageLoop System.Windows.Forms.Application.RunDialog


between the ShowDialog and the FormClosing.

  • CloseReason is "None"
  • Load runs to the end, as does VisibleChanged (though Activated never gets called).
  • There's no sign of any Exceptions being thrown.
  • Intellitrace doesn't show anything going on.
  • After the form closes, the DialogResult is "Cancel" (There's no reference to DialogResult in the form or its Designer)
  • I'm not doing any explicit threading

I'd appreciate any suggestions either as to what's going on or how to go about finding out.


share|improve this question
Do you have control events triggered during Form_Load (Text_Changed, Validating etc). Could be one of these events that closes the form? (Still doesn't explain why the Form.Show works) –  Steve Nov 13 '12 at 11:09
Are you using a custom contructor for this form? –  Killercam Nov 13 '12 at 14:23
It's a complicated for and lots of things are going on, but when I ran using IntelliTrace I saw only one event generated during the Load, and that event doesn't call Close() and anyway I took that code out and the problem remained. Also, I found all the calls to Close() in the code and set breakpoints on them, but none was ever reached. And as you say, it doesn't explain Show(). I do have custom c-tors, but I'm not sure what difference those would make: They're called before Load and for Show() as well. –  Michael Nov 13 '12 at 15:41
add comment

1 Answer

Well, this will probably do nobody any good, but here's how I solved the problem:

There was a line in the Load method that read

Me.Text = ""

I have no idea what it was doing there (this isn't my code, thank goodness), especially since the value gets set again later on, but taking that line out stopped the form from mysteriously closing. Go figure.

share|improve this answer
add comment

Your Answer


