473,382 Members | 1,639 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,382 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 7884
"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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.