Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application lifetime

Status
Not open for further replies.

GlynA

Programmer
May 1, 2002
77
GB
I have a VB6 application which displays a logon form which then shows the applications main form and unloads itself.
This works fine in VB 6, but when I migrate it to VB.NET the application terminates as soon as the logon form unloads.
How should I change the code to make this work as in VB6?
I have tried using Application.run to load the main form but this gives an error saying that I cannot run another process on the same thread.
 
Research in the forums. Many people have brought this issue up already.

Hint: It has to do with the fact that EVERYTHING is a class.

Kris
 
I have looked in the forums Kris, but there does not seem to be any answer to my problem.

My start up routine ("Main") loads the first form using application.load. This form then loads a second form. I can use showdialog to do this, but this leaves the first form visible, which I do not want.

My current workround is to hide the first form before displaying the second, but not to unload it until the second form is closed. This is not ideal as it leaves the first form in memory all the time the application is running, but I cannot see any other solution without restructuring the application significantly.

Has anybody got any suggestions?

Glyn.
 
I know I saw this before, but heck if I can find it now.

VB.NET does not have a forms collection any more. I think they want you to use a MDI application for stuff like this, but a lot of people do not want a MDI application.

Here is what I do (This feels like a HACK, but it works):

I start with my login screen and when they are logged in I will hide that form and show the next form. Now, the concept is to keep a count of how many forms are open and when there is only one form open you will close the application (since 1 form is the hidden form).

I have a class that holds the forms counter:
Public Class UBProcs1
Public Shared gsFrmNum As Integer
End Class

Now, All my forms are inheriated from a base form and in the base form I have the following code:
Public Sub CloseScreenMaybeApp()
If UBP1.gsFrmNum < 2 Then
Application.Exit()
End If
End Sub

Then in each form I have:
Private UBP1 As New UBProcs1()

Private Sub frmDeliquentNoticeText_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
UBP1.gsFrmNum += 1
End Sub
Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)
UBP1.gsFrmNum -= 1
CloseScreenMaybeApp()
End Sub

Kris

ps. I am interesting in hearing other solutions to this problem!!
 
I think I may be missing what you are trying to accomplish. If I am, can you explain.
Why not just make your Main form the startup object.
Show your login form as .showdialog from the Main form load event.
When you dispose your startup object the app will terminate

 
I understand what you are saying woyler, but in my application there are over 50 forms and any form can open any other form (more or less) and any number of forms can be open at any point in time.

If all you have are 2 forms then you idea is the best way to go.

Kris
 
Just a suggestion, but if you have over 50 forms, and they are all related(ie part of the same app) then for the users sake shouldn't you have a main(MDI) form for navigation purposes and such.
 
Each form shares the same treewview for navigation and by not using a MDI containter you get have different buttons in the task bar for each form open. 90% of the time there would only be one form open at a time, but for the multitasking user it allows more flexability.

I will admit there are VERY good arguements for a MDI container, but our other programs do not use it and I have to make my program follow the same guidelines as the other programs.

My personal preference would be to use MDI unless you only have one main form.

Kris
- An optimist thinks that this is the best possible world. A pessimist fears that this is true.
 
Do you ever assign values for 1 form from another form?
for example:

sub Form2_Load
Form1.Text1.text = &quot;This text came from form2&quot;
end sub

If so, are you aware that you will have to keep track of the instance of the loaded form class you are refering to.
Saying Form1.Text1.text = &quot;This text came from form2&quot; will not work the same as it does in VB6.
I mention this only because givin your above issue, this may be the next item you encounter.

 
Try the application.run command of vb.net. This will allow you to close the calling form while the called form is still running.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top