473,804 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2499
If you're doing the work without using the BackgroundWorke r component
(or a background thread, pre .Net 2) then your UI will not update while
you're running in the loop.

Use the BackGroundWorke r, 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******** *************@a 75g2000cwd.goog legroups.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 FileSystemWathe r compoenent for monitoring the file

1. You haven't set file watcher's SyncronizingObj ect - 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.Pre ocessEvents periodically from inside the loop.

--
Stoitcho Goutsev (100)

"Mo" <le******@yahoo .comwrote in message
news:11******** *************@a 75g2000cwd.goog legroups.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
1560
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 with only the timer and the label, and it works fine, is there something else I need to do with the threads to get this to work? I'm a bit lost here. Thanks in advance -- Aaryn // Code Start
3
32498
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 this in form_load void: System.Windows.Forms.Label labelArray = new System.Windows.Forms.Label; for (i=1;i<91;i++)
8
2487
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
2425
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 file. For example - FORM1 IS :
13
1739
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 ArrLabel(i).Name="Label" & i ArrLabel(i).Text="Test" & i ArrLabel(i).Show()
31
7248
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
3167
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 works fine, it seems to fire when the form changes visibility. Here is the code. Private Sub lblP1JoyUp_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles lblP1JoyUp.Paint If lblP1JoyUp.Visible = True Then Dim...
3
2426
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 why not? Below is an working VB.Net example to illustrate what I mean.
9
8030
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 ... :-)) When I set the label with "SendToBack", it completely disapears. I also tried to set the child form like "BringToFront" but this also does not help.
0
9716
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
9595
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
10354
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9177
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5536
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...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
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
3837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3005
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.