473,387 Members | 1,504 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,387 software developers and data experts.

Update a Progress Bar asynchronously

Hello

I am trying to update a Progress bar on a form. I am able to update it via using a simple clock timer, but as soon as I perform a long operation G1 (generation of a report) in a separate form, it stops updating it, but keeps on incrementing the Progress bar values in the background and displays the updated Pbar after finishing the operation G1.

My requirement is that it should update during the execution of operation G1.

On further exploration I have come to know that if I put updation of Pbar on a separate thread and use some queuing and dequeing, it would work. I have done that but behaviour remains the same. Can you Please point out where I am going wrong. I am new to Threading and Queuing.

I am attaching a part of my code. I have seen the following thread and queue are working as I have traced the flow. I may be wrong in refreshing the PBar as I have tried PBar.refresh, PBar.update after updating PBar.Value.

Dim sq as New Queu

CTimer_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs)
Tr
sField = Format(Now, "ss"
If sField = "00" The
PBar0.Value =
Els
PBar0.Value = CInt(sField
End I
PBar0.Increment(1
sq.Enqueue(PBar0.Value
End Try

Private Sub b1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Clic
Dim sT As New System.Threading.Thread(AddressOf UpdateBar
sT.Start(
End Su

Private Sub UpdateBar(
Tr
D
System.Threading.Thread.CurrentThread.Sleep(2500
If sq.Count > 0 The
PBar0.Value = sq.Dequeu
'PBar0.Update(
'PBar0.Refresh(
End I
Loo
End Tr
End Sub
Nov 20 '05 #1
3 3777
Why not try Application.DoEvents in the code for the long operation for
something this simple? Here's the documentation on it from the .NET
Framework SDK...

When you run a Windows Form, it creates the new form, which then waits for
events to handle. Each time the form handles an event, it processes all the
code associated with that event. All other events wait in the queue. While
your code handles the event, your application does not respond. For example,
the window does not repaint if another window is dragged on top.

If you call DoEvents in your code, your application can handle the other
events. For example, if you have a form that adds data to a ListBox and add
DoEvents to your code, your form repaints when another window is dragged
over it. If you remove DoEvents from your code, your form will not repaint
until the click event handler of the button is finished executing.

Typically, you use this method in a loop to process messages.

CAUTION Calling this method can cause code to be re-entered if a message
raises an event.
"Vinay" <cu****@cursor.com> wrote in message
news:B7**********************************@microsof t.com...
Hello,

I am trying to update a Progress bar on a form. I am able to update it via using a simple clock timer, but as soon as I perform a long operation G1
(generation of a report) in a separate form, it stops updating it, but keeps
on incrementing the Progress bar values in the background and displays the
updated Pbar after finishing the operation G1.
My requirement is that it should update during the execution of operation G1.
On further exploration I have come to know that if I put updation of Pbar on a separate thread and use some queuing and dequeing, it would work. I
have done that but behaviour remains the same. Can you Please point out
where I am going wrong. I am new to Threading and Queuing.
I am attaching a part of my code. I have seen the following thread and queue are working as I have traced the flow. I may be wrong in refreshing
the PBar as I have tried PBar.refresh, PBar.update after updating
PBar.Value.
Dim sq as New Queue

CTimer_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Try
sField = Format(Now, "ss")
If sField = "00" Then
PBar0.Value = 1
Else
PBar0.Value = CInt(sField)
End If
PBar0.Increment(1)
sq.Enqueue(PBar0.Value)
End Try

Private Sub b1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Click Dim sT As New System.Threading.Thread(AddressOf UpdateBar)
sT.Start()
End Sub

Private Sub UpdateBar()
Try
Do
System.Threading.Thread.CurrentThread.Sleep(2500)
If sq.Count > 0 Then
PBar0.Value = sq.Dequeue
'PBar0.Update()
'PBar0.Refresh()
End If
Loop
End Try
End Sub

Nov 20 '05 #2
Scott

Thanks for your reply. Correct me, if I am wrong, but my understanding of Application.DoEvents - one loses the control on the ongoing event execution and as the event finishes, one will not know when it is completed unless someone verifies the end product (Report in this case).

I am not using Application.DoEvents as my report generation program is creating some interim Temp files and losing the control would allow other events to get hold of these common temp files. Also use of progress bar is valid only during the period of report generation. With Application.Doevents I would not know when the report has been generated, so that I can destroy (or hide) Progress bar control.

Besides it may look simple to you but it is not looking simple to me. It was simple for me in VB6, but in VB.net I am struggling with the required functionality. I would appreciate if someone can point to me what is wrong in my current approach as given in the post.

Regard

Vinay
Nov 20 '05 #3
Hi, Vinay

Rather than creating a separate thread for your progress bar, it might make
more sense to put your report in a separate thread. Reporting is typically
a background task, so there are no display updating issues to address.

Thank you for choosing the MSDN Managed Newsgroups,

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
--------------------
| From: "=?Utf-8?B?VmluYXk=?=" <cu****@cursor.com>
| Subject: Re: Update a Progress Bar asynchronously
| Date: Thu, 26 Feb 2004 21:56:06 -0800
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Scott,

Thanks for your reply. Correct me, if I am wrong, but my understanding of
Application.DoEvents - one loses the control on the ongoing event execution
and as the event finishes, one will not know when it is completed unless
someone verifies the end product (Report in this case).

I am not using Application.DoEvents as my report generation program is
creating some interim Temp files and losing the control would allow other
events to get hold of these common temp files. Also use of progress bar is
valid only during the period of report generation. With
Application.Doevents I would not know when the report has been generated,
so that I can destroy (or hide) Progress bar control.

Besides it may look simple to you but it is not looking simple to me. It
was simple for me in VB6, but in VB.net I am struggling with the required
functionality. I would appreciate if someone can point to me what is wrong
in my current approach as given in the post.

Regards

Vinay
|

Nov 20 '05 #4

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

Similar topics

3
by: Brian Birtle | last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible to build a file upload progress meter using ASP.NET" **** First person to prove me wrong gets "All Time .NET Programming GOD"...
3
by: Pierre | last post by:
Hi, I was wondering if anyone ever done a progress bar that reflects a database update. I have an update query with SQL server that takes about 5 minutes. I can't figure out a way to show the...
2
by: Dick Swager | last post by:
I have a form with a progress bar and a label. The form launches a class that raises an event to indicate the progress. The event arguments contains integers to update the progress bar and a...
6
by: '~=_Slawek_=~' | last post by:
I have problem with SQL update. Sometimes it can take 2-10 seconds. I need to make this update every time page is opened - ASYNCHRONOUSLY. I have read forums, php.net etc about running php code...
10
by: test | last post by:
Hi, I want to asynchronously recieve large amount of data using XMLHTTPRequest. If it is possible, I would like to make a progress bar to show the user how the process is going. According to...
30
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
2
by: Rico Schäpe | last post by:
Hi, I want to show a progress dialog for long working tasks. The task should be canceled too. Inspired by the article of Chris Sells "Safe, Simple Multithreading in Windows Forms, Part 2" I've...
0
by: shapper | last post by:
Hello, I created an update progress at runtime including the progress template. When the postback is made I can see the update progress but the update panel content is also visible. I...
0
by: Bradley Plett | last post by:
I am aware that showing progress for file transfers is relatively easy with WCF since it can be done using a stream (see http://www.codeproject.com/KB/WCF/WCF_FileTransfer_Progress.aspx for a good...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
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...

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.