473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
6 7885
"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
"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matt | last post by:
Ok, this is probably a simple and stupid question, but its giving me hell. Lets say that this is my app public class myapp : System.Windows.Forms.Form { public myapp() { }
13
by: Ole Hanson | last post by:
Hi I am in need of a way to launch my WinForms-app (app.exe) just by pressing a keyboard combination like (Ctrl-Alt-P). This functionality should be present "out of the box" after the app...
2
by: Krzysztof Karnicki | last post by:
I would like develop Form on my Windows Application, that is going to notify the user, just like Microsoft Office 2003 shows that there are new mail coming. When I use System.Windows.Forms.Form and...
1
by: i | last post by:
Hi, I'm trying to get a seperate class, initialized by a form class, to manipulate certain objects on the form (ex: add to a listbox). The manipulation will occur via a thread that is not the...
7
by: Christopher C | last post by:
I am using a C# winform to launch some apps for our students. Basically the user hits a button the form hides and the app is launched. When the app exits, the form is unhidden. I have a question on...
2
by: Chris Veal | last post by:
I created a user control and drag it onto a Winform I run the app OK but when I return to the dev environment the user control disappears Has anyone seen this b4? Whats the deal with that? ...
6
by: D Witherspoon | last post by:
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...
0
by: dadizhu | last post by:
Hi, everyone. I ran into an UI freeze issue with threading and simplied the problem down to the following sample code. The logic is as follows: 1. The main UI thread creates a non-UI STA...
5
by: moondaddy | last post by:
I have a .net 2.0 winforms app that calls a web service which creates creates a GUID and caches it, then passes the GUID back to the winform. then it opens a aspx page and passes the GUID as a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.