Reputation: 2171
updater.SearchByFunctionName returns after 5-10 seconds, I want to increase the progress bar's value while it's working, but it never stops.
I'm new to threading, so maybe it's something very basic, I don't know.
Thread t = new Thread(delegate()
{
updater.SearchByFunctionName(testsuiteBox.SelectedValue.ToString(), functionNameBox.Text);
});
t.Start();
progressBar.Value = 0;
while(t.IsAlive)
{
Thread.Sleep(1000);
if (progressBar.Value >= 200 )
{
progressBar.Value = 0;
}
progressBar.Value += 20;
}
Upvotes: 0
Views: 484
Reputation: 203802
You're blocking the UI thread, and that is preventing any updates to the progressbar.
You should use a Timer
, attach an event to the Tick
event and place the code to update the progress bar in there.
It also seems that you're manually making a Marquee style progress bar. ProgressBar
has support for this built in. You can just add:
myProgressBar.Style = ProgressBarStyle.Marquee;
and you can set the MarqueeAnimationSpeed
to what is appropriate. After that you don't need to do anything for it.
Upvotes: 3