473,750 Members | 6,086 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ProgressBar Not Updating Question

Please consider:

foreach (ListViewItem item in listViewFiles.I tems)
{
// Display the ProgressBar control.
pBar1.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
pBar1.Minimum = 1;
// Set Maximum to the total number of files to copy.
pBar1.Maximum = 4; //filenames.Lengt h;
// Set the initial value of the ProgressBar.
pBar1.Value = 1;
// Set the Step property to a value of 1 to represent each file being
copied.
pBar1.Step = 1;

string source=item.Sub Items[0].Text.Trim();
string destination=ite m.SubItems[1].Text.Trim();
lisInfoList.Ite ms.Add("Copying : " + source + " to " + destination);
File.Copy(sourc e,destination,t rue);
item.SubItems[2].Text="Success" ;
// Perform the increment on the ProgressBar.
pBar1.PerformSt ep();
Application.DoE vents();
}

I set the Maximum to 4 because I know I only have 4 files for testing.
I can see the progressbar update very quickly to halfway on two of the
small files. The two larger 36MB files do not update the bar at all
until the end and then the blue bars on the ProgressBar only go up to
halfway when completed. What I am trying to do is have it so that each
file copied gets the ProgressBar a little closer to the end until they
are all copied. Thank you for any help.

Nov 17 '05 #1
8 19628
I read something about doing this in another thread. Maybe someone
knows?

Nov 17 '05 #2
Hi,

your application starts the copying processes and the display of the progess-bar from within the same thread. File-IO can be very
consumptive regarding processor-time and thus performance. I think your application is too busy with copying (especially in the case
of large files) and thus the ProgressBar is not updated.

I had a similar problem with writing video files (up to serveral hundred MBytes in size) and displaying progress in a separate form.
Only if I put the writing in a separate thread the ProgressBar in my popup-form would update correctly.

If you'll use a separate thread created from the main application for coyping, let the copying-thread call a "callback-function"
defined within the calling thread (the main application) so that the outside world of the copying-thread keeps being informed on how
far copying has proceeded.

This callback-function should then be able to update the ProgressBar.
On the other hand, just for a try:

pBar1.PerformSt ep();

pBar1.Refresh() ;
Regards
Rolf
<ne***********@ gmail.com> schrieb im Newsbeitrag news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Please consider:

foreach (ListViewItem item in listViewFiles.I tems)
{
// Display the ProgressBar control.
pBar1.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
pBar1.Minimum = 1;
// Set Maximum to the total number of files to copy.
pBar1.Maximum = 4; //filenames.Lengt h;
// Set the initial value of the ProgressBar.
pBar1.Value = 1;
// Set the Step property to a value of 1 to represent each file being
copied.
pBar1.Step = 1;

string source=item.Sub Items[0].Text.Trim();
string destination=ite m.SubItems[1].Text.Trim();
lisInfoList.Ite ms.Add("Copying : " + source + " to " + destination);
File.Copy(sourc e,destination,t rue);
item.SubItems[2].Text="Success" ;
// Perform the increment on the ProgressBar.
pBar1.PerformSt ep();
Application.DoE vents();
}

I set the Maximum to 4 because I know I only have 4 files for testing.
I can see the progressbar update very quickly to halfway on two of the
small files. The two larger 36MB files do not update the bar at all
until the end and then the blue bars on the ProgressBar only go up to
halfway when completed. What I am trying to do is have it so that each
file copied gets the ProgressBar a little closer to the end until they
are all copied. Thank you for any help.

Nov 17 '05 #3
If I do the other thread, does that mean it cannot be on the same form?

Nov 17 '05 #4
<ne***********@ gmail.com> wrote:
I read something about doing this in another thread. Maybe someone
knows?


You should definitely be performing long-running operations in a worker
thread - but then you can't update the UI directly from the worker
thread.

See http://www.pobox.com/~skeet/csharp/t...winforms.shtml for more
information.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5
<ne***********@ gmail.com> wrote:
If I do the other thread, does that mean it cannot be on the same form?


No, it just means you can't update the form directly from that thread.
You have to use Control.Invoke/BeginInvoke to marshal UI updates to the
UI thread.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
I was able to do the following:

// Display the ProgressBar control.
pBar1.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
pBar1.Minimum = 1;
// Set Maximum to the total number of files to copy.

// Set the initial value of the ProgressBar.
pBar1.Value = 1;
// Set the Step property to a value of 1 to represent each file being
copied.
pBar1.Step = 1;

try
{
foreach (ListViewItem item in listViewFiles.I tems)
{
pBar1.Maximum = listViewFiles.I tems.Count;
try
{
item.SubItems[2].Text="Copying. ..";
Application.DoE vents();
string source=item.Sub Items[0].Text.Trim();
string destination=ite m.SubItems[1].Text.Trim();
lisInfoList.Ite ms.Add("Copying : " + source + " to " + destination);
File.Copy(sourc e,destination,t rue);
item.SubItems[2].Text="Success" ;
Application.DoE vents();
// Perform the increment on the ProgressBar.
pBar1.PerformSt ep();
Application.DoE vents();

}
....

And the progressbar updates based upon the number of files I have. But
now that I think about it that's not really what I meant to do. I was
thinking I could make the progressbar update based upon how far along
the file was during the copy. So as say a 14MB file is copying it does
like windows and moves the bar until 14MB is reached. Not sure what to
calculate though. What I have above is kind of an "overall"
progressbar. I don't know if using DoEvents() is a good thing either.

Nov 17 '05 #7
In such cases (copying, writing several files) I use to update the ProgressBar according to the file size of the individual file
related to the overall size of all files.

If you want to go even deeper you would have to read a source-file block-wise into a buffer and write from that buffer blockwise to
the target file. The size of the buffer (1KB, 1 MB, ...) defines the granularity of the ProgressBar-information.

Regards

Rolf


<ne***********@ gmail.com> schrieb im Newsbeitrag news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I was able to do the following:

// Display the ProgressBar control.
pBar1.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
pBar1.Minimum = 1;
// Set Maximum to the total number of files to copy.

// Set the initial value of the ProgressBar.
pBar1.Value = 1;
// Set the Step property to a value of 1 to represent each file being
copied.
pBar1.Step = 1;

try
{
foreach (ListViewItem item in listViewFiles.I tems)
{
pBar1.Maximum = listViewFiles.I tems.Count;
try
{
item.SubItems[2].Text="Copying. ..";
Application.DoE vents();
string source=item.Sub Items[0].Text.Trim();
string destination=ite m.SubItems[1].Text.Trim();
lisInfoList.Ite ms.Add("Copying : " + source + " to " + destination);
File.Copy(sourc e,destination,t rue);
item.SubItems[2].Text="Success" ;
Application.DoE vents();
// Perform the increment on the ProgressBar.
pBar1.PerformSt ep();
Application.DoE vents();

}
...

And the progressbar updates based upon the number of files I have. But
now that I think about it that's not really what I meant to do. I was
thinking I could make the progressbar update based upon how far along
the file was during the copy. So as say a 14MB file is copying it does
like windows and moves the bar until 14MB is reached. Not sure what to
calculate though. What I have above is kind of an "overall"
progressbar. I don't know if using DoEvents() is a good thing either.


Nov 17 '05 #8
I have an article on my blog where I use some Windows API's to show a
progress bar just like Windows does. Hope this helps:

http://khsw.blogspot.com/2005/08/cop...-in-vbnet.html

--
http://www.khsw-be.net
"ne***********@ gmail.com" wrote:
Please consider:

foreach (ListViewItem item in listViewFiles.I tems)
{
// Display the ProgressBar control.
pBar1.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
pBar1.Minimum = 1;
// Set Maximum to the total number of files to copy.
pBar1.Maximum = 4; //filenames.Lengt h;
// Set the initial value of the ProgressBar.
pBar1.Value = 1;
// Set the Step property to a value of 1 to represent each file being
copied.
pBar1.Step = 1;

string source=item.Sub Items[0].Text.Trim();
string destination=ite m.SubItems[1].Text.Trim();
lisInfoList.Ite ms.Add("Copying : " + source + " to " + destination);
File.Copy(sourc e,destination,t rue);
item.SubItems[2].Text="Success" ;
// Perform the increment on the ProgressBar.
pBar1.PerformSt ep();
Application.DoE vents();
}

I set the Maximum to 4 because I know I only have 4 files for testing.
I can see the progressbar update very quickly to halfway on two of the
small files. The two larger 36MB files do not update the bar at all
until the end and then the blue bars on the ProgressBar only go up to
halfway when completed. What I am trying to do is have it so that each
file copied gets the ProgressBar a little closer to the end until they
are all copied. Thank you for any help.

Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
332
by: Maka Sili | last post by:
Using ProgressBar.Enabled = false does not dim the progress bar. There must be a way. I hope somebody could guide me. Thanks.
2
1391
by: Mayolo Juarez via DotNetMonster.com | last post by:
How i can show a progressbar when i copy a folder i use filesytemobject and i need to show the progressbar while i use the function copyfolder -- Message posted via http://www.dotnetmonster.com
3
7578
by: Stefan Turalski \(stic\) | last post by:
Hi, I used to use CopyTo() method from FileInfo class, does anyone know if there is a way to bind this with progressbar, or with some sort of paintBox - to show progress of moving/coping file ? -- best regards Stic
3
4365
by: Steve Teeples | last post by:
Is there a way for code from one class of C# to send a communication to a progressbar in another class to update the bar during runtime? -- Steve
1
2558
by: | last post by:
Hi all I am posting this to check if anyone could help me. The problem still persists. I am beginner in C#. Thanks. Subject: SQLDMO.Backup and ProgressBar - help please From: "anonymous@discussions.microsoft.com" <anonymous@discussions.microsoft.com> Sent: 11/11/2004 5:52:10 AM
2
4506
by: sotto | last post by:
I need a loginscreen, that will show a progressbar that changes values based on a method in the main application (loading data from database) how would i do this? (i guess i need threading for this) the main application shouldn't be accessible when the login password hasn't been entered correctly. anybody who can give me some help with this?
0
1551
by: Rick | last post by:
I use VB .Net and try to do som intensive actions on a database (in a seperate module). I defined an Interface for updating a progressbar on the main form. When I test it from a procedure within the Main Form Class, all works Ok. But when I use the Interface functions, the controls (ProgressBar, Textboxes) are not updated, although the ProgressBar.Value is changed. Me.Refresh(), Me.Invalidate() or Me.Update() and Appliocation.DoEvents()...
3
1360
by: al jones | last post by:
I have the following, extracted from my code (sorry, the files 'line' of code wraps across the first five lines of the copy) and pbFiles is (obviously?) the progressbar. Dim foundFiles As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles(tbSource.Text, IIf(optSubdirectories, FileIO.SearchOption.SearchAllSubDirectories, FileIO.SearchOption.SearchTopLevelOnly))
2
11122
by: =?Utf-8?B?QWFyb24=?= | last post by:
Since some controls such as the DataGridView take a long time to update themselves when performing certain tasks, I have added a StatusStrip with a ProgressBar on it. While I am updating the controls on the form, I want the ProgressBar to scroll in marquee mode. However, I cannot seem to get this to work. I set the StatusStripLabel to the text I want such as "Updating data..." and then set the ProgressBar's Style property to Marquee...
0
9004
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8841
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9587
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9346
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6086
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4718
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2229
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.