sis5
asked on
Application.Run and Form.ShowDialog
Hello there. I'll be very grateful is anyone could shed light on this problem I'm having. I'm using VB .net
This is my sub main:
while ApplicationLoop
Dim Frm1 as new Form1()
if Frm1.showdialog() = OK then
Dim Frm2 as new Form2()
Application.run(Frm2)
Frm2.dispose()
Frm2 = nothing
else
ApplicationLoop = false
end if
end while
The application runs with the intended results during the first loop - show dialog, wait for user input, if user clicks ok then display Frm2.
However, when the user closes Frm2, the second loop starts, the dialog is shown, but doesnt wait for the user input. The dialog is immediately closed, frm.showdialog evaluates to not ok and the application exits.
I'm quite sure its caused by Application.run(Frm2) because if I remove it then the dialog is displayed and waits for user input. Could someone explain why and perhaps offer a suggestion?
Thanks.
This is my sub main:
while ApplicationLoop
Dim Frm1 as new Form1()
if Frm1.showdialog() = OK then
Dim Frm2 as new Form2()
Application.run(Frm2)
Frm2.dispose()
Frm2 = nothing
else
ApplicationLoop = false
end if
end while
The application runs with the intended results during the first loop - show dialog, wait for user input, if user clicks ok then display Frm2.
However, when the user closes Frm2, the second loop starts, the dialog is shown, but doesnt wait for the user input. The dialog is immediately closed, frm.showdialog evaluates to not ok and the application exits.
I'm quite sure its caused by Application.run(Frm2) because if I remove it then the dialog is displayed and waits for user input. Could someone explain why and perhaps offer a suggestion?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried setting Frm1 to dispose and nothing, but that didn't work
I tried the showdialog too, but that didn't work either, until I got rid of an Application.Exit in Frm2. Then it worked fine.
Thanks for the solution AlexFM, but could some one explain or provide a link to what actually happens with showdialog, Application.run and Application.Exit?
Thanks.
I tried the showdialog too, but that didn't work either, until I got rid of an Application.Exit in Frm2. Then it worked fine.
Thanks for the solution AlexFM, but could some one explain or provide a link to what actually happens with showdialog, Application.run and Application.Exit?
Thanks.
I made this test, it works:
Module Module1
Public Sub Main()
Dim f1 As Form1
Dim f2 As Form2
f1 = New Form1
f2 = New Form2
While True
If f1.ShowDialog() <> DialogResult.OK Then
Exit While
End If
f2.ShowDialog()
End While
End Sub
End Module
Module Module1
Public Sub Main()
Dim f1 As Form1
Dim f2 As Form2
f1 = New Form1
f2 = New Form2
While True
If f1.ShowDialog() <> DialogResult.OK Then
Exit While
End If
f2.ShowDialog()
End While
End Sub
End Module
Try disposing and setting to nothing Frm1 too, after the End if
Dabas