473,326 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Incrementing a label on a windows form

Mo
Hi,

I am reading a line off of a local file and using it to update records
on a database table. I am using a progress bar to show the progress
which is tied to the number of records inserted. I am trying to also
show in real time the count of the records which have been processed. I
havea label on the form and in the loop I have Label1.text =
i.ToString() where i is the loop counter.I am using a file watched to
trigger the process when the file is created in the directory. It might
be something to do with the asynchronousity of the process. Any ideas/

Thanks

Jan 17 '07 #1
3 2483
If you're doing the work without using the BackgroundWorker component
(or a background thread, pre .Net 2) then your UI will not update while
you're running in the loop.

Use the BackGroundWorker, and have it raise ProgressChange events.

Andy

Mo wrote:
Hi,

I am reading a line off of a local file and using it to update records
on a database table. I am using a progress bar to show the progress
which is tied to the number of records inserted. I am trying to also
show in real time the count of the records which have been processed. I
havea label on the form and in the loop I have Label1.text =
i.ToString() where i is the loop counter.I am using a file watched to
trigger the process when the file is created in the directory. It might
be something to do with the asynchronousity of the process. Any ideas/

Thanks
Jan 17 '07 #2
Try Label1.Refresh().

However, if the label and the loop are not running in the same thread, you
may get an exception about unsafe updates and how you need to call invoke to
update the control.

For more details see:
http://msdn2.microsoft.com/en-us/lib...erequired.aspx

Robert
"Mo" <le******@yahoo.comwrote in message
news:11*********************@a75g2000cwd.googlegro ups.com...
Hi,

I am reading a line off of a local file and using it to update records
on a database table. I am using a progress bar to show the progress
which is tied to the number of records inserted. I am trying to also
show in real time the count of the records which have been processed. I
havea label on the form and in the loop I have Label1.text =
i.ToString() where i is the loop counter.I am using a file watched to
trigger the process when the file is created in the directory. It might
be something to do with the asynchronousity of the process. Any ideas/

Thanks

Jan 17 '07 #3
Mo,

What is the problem actually? I think it is that the lable doesn't update
while inside the loop.

If this is the case I can see two possible reasons. I also assume that you
use FileSystemWather compoenent for monitoring the file

1. You haven't set file watcher's SyncronizingObject - in this case the
events are fired in a worker thread and trying the change the text in the
label is wrong. Only the UI thread created the lable should alter the text

2. You have set file watcher's property and your code is executed by the UI
thread - in this case
when the program loops the application doesn't pump messages from the
message queue thus paint events are not precessed. The easiest solution is
to call Application.PreocessEvents periodically from inside the loop.

--
Stoitcho Goutsev (100)

"Mo" <le******@yahoo.comwrote in message
news:11*********************@a75g2000cwd.googlegro ups.com...
Hi,

I am reading a line off of a local file and using it to update records
on a database table. I am using a progress bar to show the progress
which is tied to the number of records inserted. I am trying to also
show in real time the count of the records which have been processed. I
havea label on the form and in the loop I have Label1.text =
i.ToString() where i is the loop counter.I am using a file watched to
trigger the process when the file is created in the directory. It might
be something to do with the asynchronousity of the process. Any ideas/

Thanks

Jan 17 '07 #4

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

Similar topics

0
by: Adonai | last post by:
Hi, I'm having an issue with this code that I'm writing, I'm curious as to why the windows form label (lblTime) isn't getting updated with the new variable when I use the timer. I made a blank form...
3
by: jhs | last post by:
Hello, I developping a .NET windows form application an need some help to create an array of System.Windows.Forms.Label in order to be able to manage all of them using index. I'm trying to do...
8
by: BillZondlo | last post by:
How come when I put the label text setting here: /// The main entry point for the application. /// </summary> static void Main() { Application.Run(new Form1()); } private void LoadInfo()
7
by: Jon S via DotNetMonster.com | last post by:
Hi all, I posted this yesterday but didnt explain it too well so thought I would do it again. I have a label on a form that I want to be able to change the text while I'm in a seperate class...
13
by: Lighting_dragon | last post by:
I try to make an array of label as this. Dim ArrLabel(10) as System.Windows.Forms.Label For i =0 to 10 ArrLabel(i) = New System.Windows.Forms.Label ArrLabel(i).Left=25 ArrLabel(i).Top=25*i...
31
by: jcrouse | last post by:
Is there a quick and easy way to change the color of a label controls border from the default black to white? Thank you, John
6
by: jcrouse | last post by:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax. I don't really understand the event. Where it...
3
by: Neil Wallace | last post by:
Hi, This is an odd one. I've been struggling to get "double click" to work well for my controls. The same event handler works perfectly for buttons, but not for labels. Can anyone tell me...
9
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have a MDI Container Form, with one label control on the Background of this container form. When I now open a child form, this form is behind the label ... and this looks ugly ... :-))...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.