472,789 Members | 1,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 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 7850
"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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.