how to display rotating globe (or other) to show activity

G

Guest

Can anyone point me to a resource that describes how to spawn a thread that
allows an image (such as a rotating globe) to launch, while an application is
processesing (probably on another thread)?

My issue is that a user action (such as a double click on a row in a grid)
is freezing my app while the action loads another form. I would like to
provide visual evidence that action is occuring.

thanks

K
 
B

Bob Powell [MVP]

This is a Windows Forms group. The OP needs info on winforms threading
methinks.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
B

Bob Powell [MVP]

Your request is a bit topsy-turvey because a thread running on it's own and
showing activity would probably run quite happily with the UI thread crashed
or stalled.

A typical way to do this sort of task is to have the activity, which is
probably running in a loop fetching data or doing other processing, invoke a
delegate or simply call a method in the main form or a specific control on
the UI thread.

Remember that the UI runs on a particular thread and will not correctly
process method calls from other threads. The Invoke mechanism is provided to
enable some thread other than the UI thread to make method calls or adjust
properties.

For example. A form with the method UpdateProgress() would spawn a thread to
do some lengthy processing. The thread would have a reference to the form
and use Invoke to call UpdateProgress each time round it's loop.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

Bob

Do you have any examples of using BeginInvoke?

I've tried creating a new thread off of the main UI thread (which opens the
new form), and in this new thread, processesing my progress bar. I'm getting
two behaviors that are strange. #1, if I use a timer to process the progress
bar, nothing happens at all. #2, if I create my own looping structure to
process the progress bar, it works, but when the new form is opened, I lose
all context and the ability to view the progress bar.. which is the original
challenge.
 
L

Lloyd Dupont

I have to disagree with you here.
You could have multiple UI thread. The anciliary one being run with a
ShowDialog() (instead of Application.Run()), as it is described in all
splash screen samples.
Even those from MSDN.

InvokeRequired is also inappropriate at startup time, where Aplication.Run()
has not even been called yet!


you could use a splash form even before Application.Run() ;-)

=== Warining: pseudo code below ==========
public class SplashForm : Form
{
Thread localUiThread;
public void ShowSplash()
{
if(localUiThread != null)
return;
localUiThread = new Thread(delegate() { ShowDialog(); });
localUiThread.Start();
}
public void HideSplash()
{
if(localUiThread == null)
return;
BeginInvoke(new MethodInvoker(delegate() { ThreadStop(); }));
}
void ThreadStop()
{
if(IsDisposed)
return;
Close();
}
}
 
G

Guest

I'm still having a problem with my splash screen "freezing" when the new form
is instanitated and loaded. I've tried lots of things, and nothing is
working.

Here's what I'm doing:

step1) On the UIThread, create new instance of my splash screen form.
When this form loads, a progress bar begins filling back and forth.

step2) On a new thread, create an instance of the form I'm trying to load.
I'm using VB.NET, and it looks as such:

dim t as thread
t = new thread(addressof [my procedure])
t.start()
 
L

Lloyd Dupont

You get it all wrong!!
The Splash screen is the one to be launched in an ancilary thread not your
main code!)!
please use the SplashForm I provided you and it will just work very
simply...


something like that:
main()
{
SplashForm sf = new SplashForm();
sf.Show();


MyForm f = new MyForm();
f.Show();
// do lengthy initialization stuff....

sf.HideSplash();
Application.Run(f);
}


--
If you're in a war, instead of throwing a hand grenade at the enemy, throw
one of those small pumpkins. Maybe it'll make everyone think how stupid war
is, and while they are thinking, you can throw a real grenade at them.
Jack Handey.
KMiller said:
I'm still having a problem with my splash screen "freezing" when the new
form
is instanitated and loaded. I've tried lots of things, and nothing is
working.

Here's what I'm doing:

step1) On the UIThread, create new instance of my splash screen form.
When this form loads, a progress bar begins filling back and forth.

step2) On a new thread, create an instance of the form I'm trying to
load.
I'm using VB.NET, and it looks as such:

dim t as thread
t = new thread(addressof [my procedure])
t.start()

--------------

When I do this, the splash screen is visible, but the progress bar doesn't
start filling until the form I'm loading on the new thread is complete.




Lloyd Dupont said:
I have to disagree with you here.
You could have multiple UI thread. The anciliary one being run with a
ShowDialog() (instead of Application.Run()), as it is described in all
splash screen samples.
Even those from MSDN.

InvokeRequired is also inappropriate at startup time, where
Aplication.Run()
has not even been called yet!


you could use a splash form even before Application.Run() ;-)

=== Warining: pseudo code below ==========
public class SplashForm : Form
{
Thread localUiThread;
public void ShowSplash()
{
if(localUiThread != null)
return;
localUiThread = new Thread(delegate() { ShowDialog(); });
localUiThread.Start();
}
public void HideSplash()
{
if(localUiThread == null)
return;
BeginInvoke(new MethodInvoker(delegate() { ThreadStop(); }));
}
void ThreadStop()
{
if(IsDisposed)
return;
Close();
}
}
 

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