|
I am working on a VB application where when a certain condtition is met, the Form cannot close itself:
Me.Close() //does not do anything
Application.Exit() //works but causes an error, due to other code checking when the main form closes
It almost seems like a silent error or something that messes up the running application.
I was just about to start looking for anything unique as to why this wouldn't work in my code, but there is a lof of different things to go through. Therefore, I thought I would ask and see if anyone had been in similiar situations and to hear how/if they solved the problem.. |
| MigrationUser 1 Friday, February 07, 2003 1:18 PM |
I has to do when something's hanging around that shouldn't be.
Only times I've seen it happen is when a form calls a method that then closes the form that called it. You have to avoid that to get it to work. If you're not doing that, then I'm not sure
<edit>
One other case I've seen it on is when adding user controls to panels, sometimes even if you remove them before unloading the form the panel is on, it's possible it could still be hanging around
but yah, I'd say it definitely has to do with something hanging around that shouldn't.
</edit> |
| MigrationUser 1 Friday, February 07, 2003 1:20 PM |
Well Hey Mr.HumanCompiler Moderator,
you knew I knew that much :)
No, this form is trying to close itself while handling an event of a usercontrol.
I'll just run through the code and see what I find. |
| MigrationUser 1 Friday, February 07, 2003 1:27 PM |
hello, hello :)
well then i'd say that's your problem, the event is still hanging around because the form hasn't closed yet.
when the event of the user control is called, it tries to close the form, well, the user control is sitting on the form, so when closing, the form tries to destroy itself, but it can't because that user control is still executing code, so it hangs around, but the form is gone.
it would be nice in the future if MS could prevent this from happening, but we'll see ;) |
| MigrationUser 1 Friday, February 07, 2003 1:31 PM |
Try forcing the window to close. This should do the trick:
Public Enum WinMsg WM_CLOSE = &H10 End Enum
Protected Overrides Sub WndProc(ByRef msg As System.Windows.Forms.Message) MyBase.WndProc(msg)
Dim wMsg As WinMsg = CType(msg.Msg, WinMsg) If msg.Msg = wMsg.WM_CLOSE Then ' Put any calls to clean-up code here
PostQuitMessage(0) End If End Sub
<System.Runtime.InteropServices.DllImport("User32.dll")> _ Public Shared Sub PostQuitMessage(ByVal nExitCode As Integer) End Sub
|
| MigrationUser 1 Sunday, February 09, 2003 10:45 PM |
Another way for a Form to get into this state is to delete a control while it still has focus.
The workaround for this is ovious enough, just pick another control on your Form and give it focus.
- mike |
| MigrationUser 1 Wednesday, February 12, 2003 6:31 PM |
I'll look into that possibility, mike.
I am thinking that it still has to do with some silent error (not that it makes sens that one would exist) because, even though I can skip the close and go to Application.Exit(); this "error" comes back to haunt me and causes other parts of the app to not work.
I am thinking that it is just something in our business layer that is not working properly.
I'll reveal the mystery when I find it. |
| MigrationUser 1 Thursday, February 13, 2003 10:15 AM |