
Forms, primary thread closing when closing startup form
But that doesn't work either. I tried several versions of the code
(declaring form1 and form2 in the module or not in various combinations) and
ended up with this sub main (as the startup object):
Module Module1
Public Myform2 As New Form2()
Sub main()
Application.Run(New Form1()) ; Why do I have a New here and your example
doesn't?
End Sub
End Module
Form1 runs and a button on form1 shows form2. But closing form1 still kills
the app even though form2 is still running and is not even declared by
form1.
I tried a do loop (doing nothing) after the application.run in main, and
that is even odder. Closing form1 still kills form2, and the app continues
to run doing nothing.
No, now I am thoroughly confused.
Quote:
> You are very close on your thread thoughts, but it is not a threading
issue.
> The issue is that if you start your application by pointing to a form as
the
> startup object, then the message pump is totally handled by that form.
You
> close the form , the message pump goes away. No message pump and the rest
> of the application fails. The recommended way to handle this is to create
a
> module with the following in it.
> Sub Main
> Application.Run(form1)
> end Sub
> and set that as the startup object.
> HTH
> > Hello,
> > When you make a project that consists of two forms, of which form1 is
the
> > startup form. When you run the application and then code the following
> under
> > a button under form1:
> > form2.show
> > form1.close
> > The program closes down, I think this is because the form1 runs in the
> > primary thread , and when it is closed , the primary thread end and all
> > 'secondary' once ( like the one with the form2 ) end too.
> > You could solve this in multiple ways, like setting form2 as your
startup
> > form and keep it hidden, or to keep form1 in memory by hiding it instead
> of
> > closing. But these are all ways round the problem.
> > So, what I would like is a clean solution which faces the problem as it
> is.
> > Can anyone help me ?
> > Can anyone validate my thread explaination ?
> > Thx in Advance,
> > -----------
> > Tom Deseyn