dinoboy Posted July 26, 2005 Posted July 26, 2005 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... Quote
jmcilhinney Posted July 26, 2005 Posted July 26, 2005 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. Quote
dinoboy Posted July 26, 2005 Author Posted July 26, 2005 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. Quote
dinoboy Posted July 26, 2005 Author Posted July 26, 2005 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.