By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,217 Members | 1,227 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,217 IT Pros & Developers. It's quick & easy.

Launch winform in new thread - form wont stay open - just dissapears

P: n/a
My application takes 5 or 6 seconds to load because of the time required to
communicate with web services and load from the database. In the meantime
I'd like to show a splash screen in a seperate thread.

I am trying the following code and it shows the form for a split second and
then dissapears. Can someone help me out with what I'm doing wrong here.

Thanks,

Dan

Public Sub Main()

Dim t As New System.Threading.Thread(AddressOf OpenSplash)

t.IsBackground = False

t.ApartmentState = Threading.ApartmentState.STA

t.Start()

'do tons of work when loading app 'cut for brevity.. 'takes 5-7 seconds
of loading time

'CloseSplash

End Sub

Public Sub OpenSplash()

fSplash = New frmSplash

fSplash.Visible = True

fSplash.Show

End Sub
Jul 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"D Witherspoon" <dw**********@noway.org> schrieb:
My application takes 5 or 6 seconds to load because of the time required
to communicate with web services and load from the database. In the
meantime I'd like to show a splash screen in a seperate thread.


Instead of showing the window in a separate thread, show the window in the
application's main UI thread and perform the lengthly operation in a
separate worker thread. Your application is lacking a message loop for the
thread the 2nd form is shown from and thus the form will be closed
immediately.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jul 21 '05 #2

P: n/a
"D Witherspoon" wrote:
My application takes 5 or 6 seconds to load because of the time required to
communicate with web services and load from the database. In the meantime
I'd like to show a splash screen in a seperate thread.

I am trying the following code and it shows the form for a split second and
then dissapears. Can someone help me out with what I'm doing wrong here.


Why do you want the splash screen to be in a separate thread?

Your problem is down to the fact that in order to survive a message loop is
needed to handle messages sent by windows. You would need to use
Application.Run (hence your subsequent post :-) to get the form to hang around

James
Jul 21 '05 #3

P: n/a
You need to have a timer in the form you want to display as splash screen.
Set the time you want the window to be displayed in the timer's interval
property and close the form when the tick event fires.

Regards,
--
Angel J. HernŠndez M.
MCP - MCAD - MCSD - MCDBA
http://groups.msn.com/desarrolladoresmiranda


"D Witherspoon" <dw**********@noway.org> wrote in message
news:OV**************@TK2MSFTNGP10.phx.gbl...
My application takes 5 or 6 seconds to load because of the time required
to communicate with web services and load from the database. In the
meantime I'd like to show a splash screen in a seperate thread.

I am trying the following code and it shows the form for a split second
and then dissapears. Can someone help me out with what I'm doing wrong
here.

Thanks,

Dan

Public Sub Main()

Dim t As New System.Threading.Thread(AddressOf OpenSplash)

t.IsBackground = False

t.ApartmentState = Threading.ApartmentState.STA

t.Start()

'do tons of work when loading app 'cut for brevity.. 'takes 5-7 seconds
of loading time

'CloseSplash

End Sub

Public Sub OpenSplash()

fSplash = New frmSplash

fSplash.Visible = True

fSplash.Show

End Sub

Jul 21 '05 #4

P: n/a
It has to be in a seperate thread. Otherwise the windows contents of the
splash screen to not refresh quick enough for viewing pleasure. The thread
is too busy doing other application startup duties.
"James Mahoney" <james@domain_name_in_signiture.com> wrote in message
news:DF**********************************@microsof t.com...
"D Witherspoon" wrote:
My application takes 5 or 6 seconds to load because of the time required
to
communicate with web services and load from the database. In the
meantime
I'd like to show a splash screen in a seperate thread.

I am trying the following code and it shows the form for a split second
and
then dissapears. Can someone help me out with what I'm doing wrong here.


Why do you want the splash screen to be in a separate thread?

Your problem is down to the fact that in order to survive a message loop
is
needed to handle messages sent by windows. You would need to use
Application.Run (hence your subsequent post :-) to get the form to hang
around

James

Jul 21 '05 #5

P: n/a
Beautiful ..

"James Mahoney" <james@domain_name_in_signiture.com> wrote in message
news:DF**********************************@microsof t.com...
"D Witherspoon" wrote:
My application takes 5 or 6 seconds to load because of the time required
to
communicate with web services and load from the database. In the
meantime
I'd like to show a splash screen in a seperate thread.

I am trying the following code and it shows the form for a split second
and
then dissapears. Can someone help me out with what I'm doing wrong here.


Why do you want the splash screen to be in a separate thread?

Your problem is down to the fact that in order to survive a message loop
is
needed to handle messages sent by windows. You would need to use
Application.Run (hence your subsequent post :-) to get the form to hang
around

James

Jul 21 '05 #6

P: n/a
Or alternately, you can fire an event from Sub Main that is handled in the
Splash Thread to close the Splash thread (you would have to show the Splash
form as a .showdialog in the splash thread though.

"Angel J. Hern√°ndez M." wrote:
You need to have a timer in the form you want to display as splash screen.
Set the time you want the window to be displayed in the timer's interval
property and close the form when the tick event fires.

Regards,
--
Angel J. Hern√°ndez M.
MCP - MCAD - MCSD - MCDBA
http://groups.msn.com/desarrolladoresmiranda


"D Witherspoon" <dw**********@noway.org> wrote in message
news:OV**************@TK2MSFTNGP10.phx.gbl...
My application takes 5 or 6 seconds to load because of the time required
to communicate with web services and load from the database. In the
meantime I'd like to show a splash screen in a seperate thread.

I am trying the following code and it shows the form for a split second
and then dissapears. Can someone help me out with what I'm doing wrong
here.

Thanks,

Dan

Public Sub Main()

Dim t As New System.Threading.Thread(AddressOf OpenSplash)

t.IsBackground = False

t.ApartmentState = Threading.ApartmentState.STA

t.Start()

'do tons of work when loading app 'cut for brevity.. 'takes 5-7 seconds
of loading time

'CloseSplash

End Sub

Public Sub OpenSplash()

fSplash = New frmSplash

fSplash.Visible = True

fSplash.Show

End Sub


Jul 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.