469,627 Members | 1,103 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,627 developers. It's quick & easy.

Thread Loading Form

I have a form with a loading bar as marquee so i don't need to play
with the progress thing. It's just a form to show activity in other
way.

So what i need to do is start it at the beginning of the process which
take 10-30 sec depends and have to stop it at the end. I have to use
thread so i can see activity. I just have a little problem. when i
call my thread i see the form appearing and disappearing real fast
(like a quarter second). i havent been able to identify exactly the
problem but i think is because when thread reach end of his function
it stop by itself. I can understand that it;s logic. so here what i
use so far.

//Main declaration

Private frmModelSelectionLoadingBar LoadingBar;

//the function the thread trigger, i found that the form
//need to be instanciate in the thread or else it doesn't work

private void StartLoadingbar()
{
LoadingBar = new frmModelSelectionLoadingBar();
LoadingBar.Show();
}

//before i start running my code

Thread t = new Thread(new ThreadStart(StartLoadingbar));
t.Start();

// when it get under this line the form already disappear and
// at the end of my long code i put:

t.Suspend();

this give me error, so that's why i think when he run the function
StartLoadingBar
and finish it stop the thread automatically. So is what i found out is
right ? and
how could i fix this, i tought of a loop in the function but this is
going to slow down. Maybe a wait loop but how to make this and sheck
for a bool variable that i would change. i don't know, there must be a
better wait of coding that ?
Nov 19 '07 #1
1 5385
You have this set up a bit backward. You're creating the a UI element
(the loading form) on a separate thread and doing the work on your UI
thread. Also, you could make things a bit easier on yourself by using
the BackgroundWorker class.

http://msdn2.microsoft.com/en-us/lib...undworker.aspx

On Nov 19, 9:07 am, Franck <the_darkbl...@hotmail.comwrote:
I have a form with a loading bar as marquee so i don't need to play
with the progress thing. It's just a form to show activity in other
way.

So what i need to do is start it at the beginning of the process which
take 10-30 sec depends and have to stop it at the end. I have to use
thread so i can see activity. I just have a little problem. when i
call my thread i see the form appearing and disappearing real fast
(like a quarter second). i havent been able to identify exactly the
problem but i think is because when thread reach end of his function
it stop by itself. I can understand that it;s logic. so here what i
use so far.

//Main declaration

Private frmModelSelectionLoadingBar LoadingBar;

//the function the thread trigger, i found that the form
//need to be instanciate in the thread or else it doesn't work

private void StartLoadingbar()
{
LoadingBar = new frmModelSelectionLoadingBar();
LoadingBar.Show();

}

//before i start running my code

Thread t = new Thread(new ThreadStart(StartLoadingbar));
t.Start();

// when it get under this line the form already disappear and
// at the end of my long code i put:

t.Suspend();

this give me error, so that's why i think when he run the function
StartLoadingBar
and finish it stop the thread automatically. So is what i found out is
right ? and
how could i fix this, i tought of a loop in the function but this is
going to slow down. Maybe a wait loop but how to make this and sheck
for a bool variable that i would change. i don't know, there must be a
better wait of coding that ?
Nov 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Jason Jacob | last post: by
5 posts views Thread by Roman | last post: by
3 posts views Thread by John Wright | last post: by
10 posts views Thread by Paul E Collins | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.