473,473 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Label changes not being reflected until loop is done

Hi All,

I am making a file manager type of application and am trying to
duplicate Windows Explorer's behaviour when copying files; ie, display
a second form with the copy files animation. As it is copying files,
it should show the file name and folder. For testing purposes I am
sleeping for 1 second to simulate a file being copied. My problem is
that when I run the code, the labels do not change to reflect the file
names until the very end, when only the last filename will be
reflected. However, if I put a message box before the sleep, the
labels get set as I expected. I have tried using a timer and a long
loop instead of the sleep, and I have also tried a textbox instead of a
label, but all produce the same behaviour. Here is the offending code
- it is called by a loop which loops through all the files to be
copied.
Public Sub ProcessFile(ByVal root As String, ByVal pathToFile As
String)
Dim fi As New FileInfo(pathToFile)
lblFileBeingProcessed.Text = fi.Name
lblFromDirectoryToDirectory.Text = "From '" & root & "' to '" &
root & "'"
'MsgBox("Copy File: " & root & fi.Name)
System.Threading.Thread.Sleep(1000) ' Sleep for 1 second
bytesProcessed += fi.Length
ProgressBar1.Value = Math.Min(100, Math.Round(bytesProcessed /
bytesToProcess * 100))
myParentForm.ListBox1.Items.Add("Copy File: " & root & fi.Name)
End Sub

Thank you

Aug 14 '06 #1
3 2076
Hello pe********@rci.rogers.com,

The label gets updated when the message to repaint it is processed. So massage
the message pump. Application.DoEvents.

-Boo
Hi All,

I am making a file manager type of application and am trying to
duplicate Windows Explorer's behaviour when copying files; ie, display
a second form with the copy files animation. As it is copying files,
it should show the file name and folder. For testing purposes I am
sleeping for 1 second to simulate a file being copied. My problem is
that when I run the code, the labels do not change to reflect the file
names until the very end, when only the last filename will be
reflected. However, if I put a message box before the sleep, the
labels get set as I expected. I have tried using a timer and a long
loop instead of the sleep, and I have also tried a textbox instead of
a label, but all produce the same behaviour. Here is the offending
code - it is called by a loop which loops through all the files to be
copied.

Public Sub ProcessFile(ByVal root As String, ByVal pathToFile As
String)
Dim fi As New FileInfo(pathToFile)
lblFileBeingProcessed.Text = fi.Name
lblFromDirectoryToDirectory.Text = "From '" & root & "' to '" &
root & "'"
'MsgBox("Copy File: " & root & fi.Name)
System.Threading.Thread.Sleep(1000) ' Sleep for 1 second
bytesProcessed += fi.Length
ProgressBar1.Value = Math.Min(100, Math.Round(bytesProcessed /
bytesToProcess * 100))
myParentForm.ListBox1.Items.Add("Copy File: " & root & fi.Name)
End Sub
Thank you

Aug 14 '06 #2
Thanks. That worked perfectly.

GhostInAK wrote:
Hello pe********@rci.rogers.com,

The label gets updated when the message to repaint it is processed. So massage
the message pump. Application.DoEvents.

-Boo
Hi All,

I am making a file manager type of application and am trying to
duplicate Windows Explorer's behaviour when copying files; ie, display
a second form with the copy files animation. As it is copying files,
it should show the file name and folder. For testing purposes I am
sleeping for 1 second to simulate a file being copied. My problem is
that when I run the code, the labels do not change to reflect the file
names until the very end, when only the last filename will be
reflected. However, if I put a message box before the sleep, the
labels get set as I expected. I have tried using a timer and a long
loop instead of the sleep, and I have also tried a textbox instead of
a label, but all produce the same behaviour. Here is the offending
code - it is called by a loop which loops through all the files to be
copied.

Public Sub ProcessFile(ByVal root As String, ByVal pathToFile As
String)
Dim fi As New FileInfo(pathToFile)
lblFileBeingProcessed.Text = fi.Name
lblFromDirectoryToDirectory.Text = "From '" & root & "' to '" &
root & "'"
'MsgBox("Copy File: " & root & fi.Name)
System.Threading.Thread.Sleep(1000) ' Sleep for 1 second
bytesProcessed += fi.Length
ProgressBar1.Value = Math.Min(100, Math.Round(bytesProcessed /
bytesToProcess * 100))
myParentForm.ListBox1.Items.Add("Copy File: " & root & fi.Name)
End Sub
Thank you
Aug 15 '06 #3
GhostInAK wrote:
Hello pe********@rci.rogers.com,

The label gets updated when the message to repaint it is processed. So massage
the message pump. Application.DoEvents.
Be careful with DoEvents in a loop, it can allocate more memory than a
simple Sleep(0) call. You could also call the Refresh method on the
label which should work as well. See the following links about
DoEvents:

http://blogs.msdn.com/tmiller/archiv.../07/57524.aspx
http://www.codinghorror.com/blog/archives/000159.html

Aug 16 '06 #4

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

Similar topics

16
by: Alvin Bruney | last post by:
I'm observing that a sleeping thread changes to stopped after a while. Is that accepted framework behavior for web applications? My thread basically does some work, and sleeps for 60 minutes...
3
by: kaiser | last post by:
Hello, Am new to C# and am playing around trying to get a while loop to display a int on a windows console using label. private void btnGo_Click(object sender, System.EventArgs e) { int Counter...
1
by: Henke | last post by:
Hello, I have one ImageButton controls which I initialize in Page_Load and declare on class level. ImageButton save = new ImageButton(); save.ImageUrl = "save.gif" save.Click += new...
1
by: nospamjac | last post by:
Hi, Is there a way to update the text of an asp:label on a webform without refreshing the entire page? What is called by button clicks and other events that refresh a webform control? See the...
1
by: ngreplies | last post by:
I am using a label as a tooltip box because I need to be able to change the background of the box depending on the information it is representing. That aside, I need to be able to auto-size the...
24
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I have a hidden input field in a form which I change in some occasions on the client using javascript, but when I use "view source" I can't see these changes reflected on the page!...
2
by: =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post by:
Hi, I have a Label on a Windows form (Version 1.1.4322) and while I iterate recursively through a method I want to show the name of the current file being copied to another directory. The...
4
by: directory | last post by:
hey guys, I've got a weird one for ya....i have a form which takes user input in the form of textbox's etc. It then grabs some details from a file and updates some of the labels with some info...
3
by: crjunk | last post by:
Hi Everyone, I have a web form that I would like to enhance. What I'd like to do is this: A user adds/edits the text in a textbox. I want the adjoining label to change color. Example: User...
0
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...
0
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,...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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...

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.