Progressbar behaves strangely

Posted by wanderameise on Stack Overflow See other posts from Stack Overflow or by wanderameise
Published on 2011-02-12T22:43:56Z Indexed on 2011/02/12 23:25 UTC
Read the original article Hit count: 179

Filed under:
|
|

I just created an application in C# that uses a thread which polls the UART for a receive event. If data is received an event is triggered in my main thread (GUI) and a progress bar is controlled via PerformStep() method (of course, I previously set the Max value accordingly). PerformStep is invoked using the following expression to handle cross threading

this.Invoke((Action)delegate{progressBar2.PerformStep();})

When running this application the progressbar never hits its final value. It stops at 80%. When debugging and stopping at the line mentioned above, everything works fine using single steps. I have no idea what is going one!

Start read thread on main thread:

pThreadWrite = new Thread(new ThreadStart(ReadThread));
pThreadWrite.Start();

Read Thread:

private void ReadThread()
{
while(1)
{
    if (ReceiveEvent)
    {       
    FlashProgressBar();
    }
}
}

Event that is triggered in main thread:

private void FlashProgressBar()
{
this.Invoke((Action)delegate { progressBar2.PerformStep();});
} 

(It's a simplified representation of my code) It seems as if the internal progress is faster than the visual one.

© Stack Overflow or respective owner

Related posts about c#

Related posts about multithreading