-
OK.. So Stupid but
OK,
I knew I should have paid more attention to the basics of VB.Net versus
ASP.NEt but... I have a simple problem. I have project. I have a sub
main in a module. In the sub main, I declare two public variable and declare
them as new instances of one of each of the form classes I have in my probject.
In the sub main, I call the show method on both of the forms. Now, the
forms do show but only for a second. As soon the I reach the End Sub for
the Sub Main procedure, the forms go aways and my project stops running.
Can anyone fill me in on what I am doing wrong?
Thanks
George Ceaser
-
Re: OK.. So Stupid but
> In the sub main, I call the show method on both of the forms.
> Now, the forms do show but only for a second. As soon the I
> reach the End Sub for the Sub Main procedure, the forms go
> away and my project stops running.
George: Look up Application.Run in VB.NET's online help.
--
Phil Weber
-
Re: OK.. So Stupid but
Let me guess, you declare these two form variables INSIDE the code of Sub
Main() -- Right? They are then LOCAL to Sub Main, and as soon as Sub Main
reaches its end, they go out of scope and naturally DIE, EXACTLY as they
should. If on the Otherhand,, you declare then OUTSIDE of Sub Main, then
they have "global" scope, and only die when a) you cause them to close, or
b) the Program is Terminated.
Arthur Wood
"George Ceaser" <GCeaser@aol.com> wrote:
>
>OK,
>
> I knew I should have paid more attention to the basics of VB.Net versus
>ASP.NEt but... I have a simple problem. I have project. I have a sub
>main in a module. In the sub main, I declare two public variable and declare
>them as new instances of one of each of the form classes I have in my probject.
> In the sub main, I call the show method on both of the forms. Now, the
>forms do show but only for a second. As soon the I reach the End Sub for
>the Sub Main procedure, the forms go aways and my project stops running.
> Can anyone fill me in on what I am doing wrong?
>
>Thanks
>George Ceaser
-
Re: OK.. So Stupid but
Well,
In response to the one person's question, no the variables are declared
outside the sub main with a public scope. This is one of the reasons I am
so baffled that they are shutting down when I hit the end sub. I do not
want to use the application Run because that appears to run syncornously
(in other words, the second form would not run until I close the first form)
or at least that is what happened when I tried it before. Any other ideas??
"George Ceaser" <GCeaser@aol.com> wrote:
>
>OK,
>
> I knew I should have paid more attention to the basics of VB.Net versus
>ASP.NEt but... I have a simple problem. I have project. I have a sub
>main in a module. In the sub main, I declare two public variable and declare
>them as new instances of one of each of the form classes I have in my probject.
> In the sub main, I call the show method on both of the forms. Now, the
>forms do show but only for a second. As soon the I reach the End Sub for
>the Sub Main procedure, the forms go aways and my project stops running.
> Can anyone fill me in on what I am doing wrong?
>
>Thanks
>George Ceaser
-
Re: OK.. So Stupid but
There are many ways to handle this. Here are a few. To show both forms at
the same time at startup, you can:
(1) Start one form using the Application.Run() method and create/display the
second form in the code of the first form
(2) Show one of the forms using Show() in your Sub Main method and the other
(the second form)
using Application.Run().
(3) Designate one of the forms as your startup object (right-click on the
project item in the Solution Explorer if you're using VS) rather than Sub
Main, and create/display the other one in the code of that first form.
Here's an example of (2):
Sub main()
Dim f1 As New Form1()
Dim f2 As New Form2()
f2.Show()
Application.Run(f1)
End Sub
You can also start both forms on separate threads. This works very nicely,
as both forms run completely independently, and the application doesn't end
until the user closes both forms--but it also imposes limitations on how you
can interact with the forms, and may cause other resource contention or
synchronization problems in your application. (see the System.Threading
namespace for details). Here's an example:
Imports System.Threading
Module Module1
Dim f1 As Form1
Dim f2 As Form2
Sub main()
Dim t1 As Thread = New Thread(AddressOf runForm1)
Dim t2 As Thread = New Thread(AddressOf runForm2)
f1 = New Form1()
f2 = New Form2()
t1.Start()
t2.Start()
End Sub
Sub runForm1()
Application.Run(f1)
End Sub
Sub runForm2()
Application.Run(f2)
End Sub
End Module
Finally, you can show both forms using Show and use Application.DoEvents in
a
loop after that within your Sub Main method to make the application wait
until one or both of the forms close:
Sub main()
Dim f1 As New Form1()
Dim f2 As New Form2()
f1.Show()
f2.Show()
Do While ((f1.IsDisposed = False) Or (f2.IsDisposed = False))
Application.DoEvents()
Loop
End Sub
"George Ceaser" <GCeaser@aol.com> wrote in message
news:3d9ca0d5$1@10.1.10.29...
>
> OK,
>
> I knew I should have paid more attention to the basics of VB.Net versus
> ASP.NEt but... I have a simple problem. I have project. I have a sub
> main in a module. In the sub main, I declare two public variable and
declare
> them as new instances of one of each of the form classes I have in my
probject.
> In the sub main, I call the show method on both of the forms. Now, the
> forms do show but only for a second. As soon the I reach the End Sub for
> the Sub Main procedure, the forms go aways and my project stops running.
> Can anyone fill me in on what I am doing wrong?
>
> Thanks
> George Ceaser
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|