Problem with Thread

U

Uwe

Hello,
I have an application in which I want to show a loadscreen. (I'm loading
data from the WEB and as long the app load the data I show an animated
screen which says Loading Data. I used a thread for this. It works fine on a
machine where I have installed Visual Studio (2005 or 2008) as EXE or within
VS.

I run it o n a machine where Visual Studio is not installed it crashes when
I try to start the wait screen (after closing) a second time, or the
application crashed when I close it if I only strat the screen one times.

I got the typical DW20.exe error message.

Thats the code:


C#-Code:
Thread LoadThread = new Thread(new ThreadStart(ShowLoadScreen));
LoadThread.IsBackground = true;
LoadThread.SetApartmentState(ApartmentState.STA);
LoadThread.Start();

... Aktionen ...

LoadThread.Abort();
fWait.Close();


ShowLoadScreen()
{
fWait = new frmWait();
fWait.ShowDialog();
fWait = null;
}



What may I do against ?

Thanks and regards
Uwe
 
N

Nicholas Paldino [.NET/C# MVP]

What you want to do is actually show the form on the UI thread, but then
perform the work on another thread. If you need to update the UI, you would
call Invoke from the background thread to update the UI.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


You do not really need a thread, in this case you need a splash window.

The reason is that you cannot do nothing until the data is loaded (at least
that is inferred from your post).
You use a thread when you have a long lasting operation and you need the UI
to remain active.

Google splash window in this NG and you will get several post of how to do
it.
 
U

Uwe

It's not really a Splash Screen. It's a wait screen during loading a grid.
Do you have any simple sample ?
Thanks and regards
Uwe
 
U

Uwe

Do you have any sample ?

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,


You do not really need a thread, in this case you need a splash window.

The reason is that you cannot do nothing until the data is loaded (at
least that is inferred from your post).
You use a thread when you have a long lasting operation and you need the
UI to remain active.

Google splash window in this NG and you will get several post of how to do
it.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Uwe said:
It's not really a Splash Screen. It's a wait screen during loading a grid.

It's the same. A splash screen is used to present something visual to the
user until the program loads. That's precisely what you want to do.
Do you have any simple sample ?

This is a post I did a time ago, it was the third entry when searching:
splash window group:microsoft.public.dotnet.languages.csharp

http://groups.google.com/group/micr...lic.dotnet.languages.csharp+#8e141a784871c790
 
U

Uwe Porsch

Thanks Ignacio,
that works, but my problem is, that my wait screen is animated. Actually a
Macromedia Flash File. When the waitscreen is shown, the animation will not
shown but only a still picture.

Is there a way to solve ?

Thanks and regards
Uwe
 
C

Creativ

My suggestion is that, the problem can be better tackled if you call
fWait.Close(). In that case the dialog will be closed normally instead
of being aborted.

Also it's better to call ShowDialog() on UI thread and let other
thread to to the work. Then you don't have to use control.Invoke().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top