Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am developing an application which makes the search request via the web service. Meanwhile the progress bar control is displayed to the user.

 

Now, I am using a timer to update the progress bar.

As far as I know, the System.Timer should start in the new thread... and here I am having a problem...

 

Start the timer:

this.timer.Interval = 100;
this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.cbProgressBar_update);
this.timer.Start();

 

And when timer elapsed, I want to update my progress bar.

The progress bar owner is the main UI thread, but the event is raised in the timer thread. So I can't call in cpProgressBar_update method just this.progressBar.PerformStep(). Am I right?

 

Should I use Invoke() methods in the raised event? I have tried different solutions I have thought about, but the results weren't what I had expected...

Posted
Strictly speaking you should always use Invoke when calling methods of controls created on another thread. I believe that this is actually enforced in .NET 2.0. Also, I've never used a Timer other than the WinForms version but in a multi-threaded environment I'd say that a System.Threading.Timer might be the way to go. No guarantees though, just a thought.
Posted
Actually I don't start any new threads. Simply Asynchronous request is made and while it is making the request I want to display to the user a progress bar. And for updating it, I use System.Timers.Timer class, whcich automatically starts in a new thread.
Posted

Finally I found what was wrong....

The problem wasn't related with the threading. It was caused by the lenght of the progress bar and it's values. When I assigned the value to 0, then it still showed one bar.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...