Wrox Programmer Forums
|
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3
This is the forum to discuss the Wrox book Beginning C# 3.0 : An Introduction to Object Oriented Programming by Jack Purdum; ISBN: 9780470261293
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 16th, 2010, 07:08 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default Progress Bar

I have got to the end of your Class chapters and you said to go away and create some programs before progressing so that is what I am doing. Currently I am working on a program which uses a web service to get some data, search that data, modify it if I find what I am looking for and then re-upload it.

I have done all of that fine but I wanted to tie in a progress bar to the UI so it doesn't look like the program has become unresponsive whilst it is performing this.

I am having trouble doing this, I need to get the bar running when I click a button to start the process now I can either get it to run *before* the method I wrote is called or *after* not during.

What do I need to look into to achieve this?
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old May 16th, 2010, 08:06 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Ok I found that I should use something called the background worker...
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old May 16th, 2010, 08:31 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Ok after doing some googling I have found that I should get the progress controlled by the main UI thread as it is part of the UI and use the Backgroundworker for my process.

I did this and it works great until I come to report the results back, the process returns an int which I update a label with to tell the user how many things were updated.

So I am getting the following exception:

"Cross-thread operation not valid: Control 'lblProgress' accessed from a thread other than the thread it was created on."
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old May 17th, 2010, 08:59 AM
Friend of Wrox
 
Join Date: Sep 2008
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default Progress bar

Threading is a useful technique to use when you expect a task to take a long time and there are other tasks to be done. However, it's not clear to me that you have other tasks to do, but rather you simply need to let the user know that the system is still working on the task at hand. If that's the case, the status bar is a control that will work. The online documentation shows how to use it.

If you really do need to use threading for some reason, that would require an answer that's a little too long to handle here. I would suggest you look at some other threading code examples (my guess is that your Invoke() method isn't being called correctly), such as you might find at CodeProject.com. For example:

http://www.codeproject.com/KB/cs/Fil...adManager.aspx

There's nothing wrong with looking (and learning) from other peoples' code.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
 
Old May 17th, 2010, 02:55 PM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

You are right I only have one process, problem is it just takes awhile. I will look into the status bar and see how I get on.

Cheers
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
need progress bar help mohiddin52 Access VBA 0 December 17th, 2009 07:37 AM
progress bar shweta10mca C# 1 December 25th, 2008 12:05 AM
Progress Bar toekneel Crystal Reports 0 October 19th, 2004 11:04 AM
Progress Bar BSkelding ASP.NET 1.0 and 1.1 Basics 3 May 4th, 2004 04:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.