Thread Loading Form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Franck

    #1

    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 frmModelSelecti onLoadingBar 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 frmModelSelecti onLoadingBar();
    LoadingBar.Show ();
    }

    //before i start running my code

    Thread t = new Thread(new ThreadStart(Sta rtLoadingbar));
    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 ?
  • wfairl@gmail.com

    #2
    Re: Thread Loading Form

    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 BackgroundWorke r class.

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



    On Nov 19, 9:07 am, Franck <the_darkbl...@ hotmail.comwrot e:
    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 frmModelSelecti onLoadingBar 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 frmModelSelecti onLoadingBar();
    LoadingBar.Show ();
    >
    }
    >
    //before i start running my code
    >
    Thread t = new Thread(new ThreadStart(Sta rtLoadingbar));
    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 ?

    Comment

    Working...