Solved

Application.Run and Form.ShowDialog

Posted on 2004-04-01
4
368 Views
Last Modified: 2006-11-17
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.
0
Comment
Question by:sis5
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 10738740
Hi sis5,
Try disposing and setting to nothing Frm1 too, after the End if

Dabas
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 10738875
Did you try to call Frm2 like Frm1 - using showdialog?
0
 

Author Comment

by:sis5
ID: 10738992
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.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10740078
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
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question