[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Progress Bar

Posted on 2010-08-18
10
Medium Priority
?
528 Views
Last Modified: 2012-05-10
Experts.

I have a project which reads and writes files. I want to give visual feedback for the process going on. I thought a Progress Bar would be the way to go. How do I go about using it? Ideally I would want the progress indicator correspond to the amount of process completed.

Do I count the number of lines before hand, set the maximum and minimum values and the increment by a certain amount?

Guidance in the right direction is greatly appreciated.

Best,
San
0
Comment
Question by:San24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 18

Accepted Solution

by:
Anil Golamari earned 576 total points
ID: 33469066
0
 
LVL 7

Assisted Solution

by:jdavistx
jdavistx earned 856 total points
ID: 33469146
Typically, you use ProgressBars inconjunction with BackgroundWorkers:
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

As your BackgroundWorker completes a task, in this case file I/O, it has the option to report its progress in which you can update a ProgressBar, notify the user, etc.

I'm not entirely sure what you're trying to do.  Are you wanting to report the progress as to the number of lines that have been read/written?
0
 

Author Comment

by:San24
ID: 33469206
@jdavistx - I thought I`ll have to use BackGroundWorker too. Yes, showing visually the amount of lines read and written is what I`m looking to do.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

Author Comment

by:San24
ID: 33469237
@lucky85 - Thanks for the links. I was hoping the links were in more detail.
0
 
LVL 18

Assisted Solution

by:Anil Golamari
Anil Golamari earned 576 total points
ID: 33469336
0
 
LVL 7

Assisted Solution

by:jdavistx
jdavistx earned 856 total points
ID: 33469395
You may find this a bit more helpful, San24.
http://www.dreamincode.net/forums/topic/112547-using-the-backgroundworker-in-c%23/

Personally, I don't think I would use a progress bar to display the progress of number of lines being read/written.  I think I would probably display the information through something like a label which displays the current line being read/written.

If you were to follow the example in the above link, then I update a Label within ProgressChanged with the current line read/written count.  Actually, I suppose you could have a lot of Progress-based information. Have a progress bar for displaying the iteration through the files being operated on, another progress bar for displaying the actual I/O to said file, and then additionally you could display the number of lines/characters read/written per file.  That may be a bit overkill, though, as it's likely your I/O is going to execute very quickly anyway.

If you find that your I/O task cannot be split up in such a way to take use of the BackgroundWorkers progress reporting method, then you could use a ProgressBar that is set to Marquee.
0
 
LVL 5

Assisted Solution

by:puffdaddy411
puffdaddy411 earned 568 total points
ID: 33474683
You can do both.  You want to ensure your Progress Bar style is set to "ProgressBarStyle.Continuous".  I converted this from VB.NET using the DevFusion page so hopefully there aren't too many errors.
=P
 
I used a datatable and used a For Each statement to go through all of the rows.  In this table, there are 80000 rows.  The progress bar flows nicely and the label updates very fast.

private string UpdateProgressMessage;

private void BGWorker_DoWork(System.Object sender, System.ComponentModel.DoWorkEventArgs e)
{
	Int64 i = 0;
	Int64 Count = DS.Tables("MasterTable").Rows.Count;


	foreach (System.Data.DataRow Row in DS.Tables("MasterTable").Rows) {
		//Your Work Here

		i += 1;
		UpdateProgressMessage = i + " / " + Count + " Rows Processed";
		BGWorker.ReportProgress((i / Count) * 100);

	}

}


private void PackageBGWorker_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
	//Set your label value to update
	PBLabel.Text = UpdateProgressMessage;

	//Set your ProgressBar value
	ProgBar.Value = e.ProgressPercentage;

}

Open in new window

0
 
LVL 5

Assisted Solution

by:puffdaddy411
puffdaddy411 earned 568 total points
ID: 33474690
Sorry for the error.  In the second section, "PackageBGWorker" should be "BGWorker" in your example.
0
 

Author Comment

by:San24
ID: 33474835
@jdavistx - . The actual information with the line or the line number number displayed on the label might not suit well for this application. It`s a good idea though. The reading and the writing takes some time, so just a visual feedback that the process is going on while the user is waiting might be good user interaction design.

Let me spend some time with Background worker and the progess bar and get back. As of now, I`ve never used them and my knowledge is nil.

@puffdaddy411 - With some changes to your code, let me try your solution. I`m not using DataTable.

@
0
 
LVL 7

Assisted Solution

by:jdavistx
jdavistx earned 856 total points
ID: 33475012
I would imagine the biggest thing you need to keep in mind when using a BackgroundWorker is that you don't directly access GUI elements within your BackgroundWorker method.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question