473,473 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to get the progress indication from a thread

I am able to simulate and run the "thread" as adviced earlier from my
previous post. Thanks for the tips.
Now I am stucked at how to get the progress status from the thread.

I have a main form that contains a datagrid, a progress bar and a button to
hold the result from long calculation.
looks like

[myDataGrid]
Item Code new cost
1 ABC <result from calculation>
2. DEF <....>
3. ..
..

[myPGB]
< and a Progress bar.......>

When the button is clicked, I will do while no end of file with the datagrid
and calculate new cost for each item and fill in back to the grid one by
one. Also, I will need to show user the progress.

Any advice?

TIA


Nov 20 '05 #1
6 1304
Hi Botak,

You know this sample from Arming Zingler?

I hope this helps?

Cor

\\\By Armin Zingler
In a new project, add a button to the Form. Also add the following code:

Private m_Thread As MyThread

Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click

m_Thread = New MyThread
AddHandler m_Thread.Progress, AddressOf OnProgress
AddHandler m_Thread.Done, AddressOf OnDone
m_Thread.Start()
End Sub

Public Delegate Sub ProgressDelegate(ByVal Progress As Integer)

Private Sub OnProgress(ByVal Progress As Integer)
If Me.InvokeRequired Then
Me.Invoke(New ProgressDelegate( _
AddressOf OnProgress _
), New Object() {Progress})
Else
Me.Button1.Text = Progress.ToString
End If
End Sub

Private Sub OnDone()
m_Thread = Nothing
End Sub
////
Class MyThread
Public Event Progress(ByVal Progress As Integer)
Public Event Done()

Private m_Thread As Thread

Public Sub Start()
m_Thread = New Thread(AddressOf ThreadStart)
m_Thread.Start()
End Sub

Private Sub ThreadStart()
Dim i As Integer
For i = 1 To 100
Thread.Sleep(100)
RaiseEvent Progress(i)
Next
RaiseEvent Done()
End Sub

End Class
///
Nov 20 '05 #2
Great code! Thanks Cor.
What if user decides to cancel the thread middle of the process?



"Cor Ligthert" <no**********@planet.nl> wrote in message
news:e#**************@TK2MSFTNGP10.phx.gbl...
Hi Botak,

You know this sample from Arming Zingler?

I hope this helps?

Cor

\\\By Armin Zingler
In a new project, add a button to the Form. Also add the following code:

Private m_Thread As MyThread

Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click

m_Thread = New MyThread
AddHandler m_Thread.Progress, AddressOf OnProgress
AddHandler m_Thread.Done, AddressOf OnDone
m_Thread.Start()
End Sub

Public Delegate Sub ProgressDelegate(ByVal Progress As Integer)

Private Sub OnProgress(ByVal Progress As Integer)
If Me.InvokeRequired Then
Me.Invoke(New ProgressDelegate( _
AddressOf OnProgress _
), New Object() {Progress})
Else
Me.Button1.Text = Progress.ToString
End If
End Sub

Private Sub OnDone()
m_Thread = Nothing
End Sub
////
Class MyThread
Public Event Progress(ByVal Progress As Integer)
Public Event Done()

Private m_Thread As Thread

Public Sub Start()
m_Thread = New Thread(AddressOf ThreadStart)
m_Thread.Start()
End Sub

Private Sub ThreadStart()
Dim i As Integer
For i = 1 To 100
Thread.Sleep(100)
RaiseEvent Progress(i)
Next
RaiseEvent Done()
End Sub

End Class
///

Nov 20 '05 #3
Hi Botak,

Normaly nothing special, when you do me.close on the mainform then
everything should be garbaged by the Garbage Collector.

Therefore it is managed code.

I hope this helps?

Cor
Nov 20 '05 #4
Hi Cor,

I tried "THREAD.ABORT" when cancel button is clicked and it closes main
form!!???

What I try to do is just to stop halfway without closing the main form.

Any idea?

Thanks



"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O4**************@TK2MSFTNGP09.phx.gbl...
Hi Botak,

Normaly nothing special, when you do me.close on the mainform then
everything should be garbaged by the Garbage Collector.

Therefore it is managed code.

I hope this helps?

Cor

Nov 20 '05 #5
Hi Botak,

Thread.abort is your main thread, when you want to abort a seperate thread,
you should use the right thread.

So this will be something as when I take the sample.
m_Thread.abort (do not expect it aborts direct in the taskmanager).

That m_Thread would be probably needed to be declared global in this case.

I hope this helps?

Cor
I tried "THREAD.ABORT" when cancel button is clicked and it closes main
form!!???

What I try to do is just to stop halfway without closing the main form.


Nov 20 '05 #6
* "Botak" <wi****@total.com.my> scripsit:
Great code! Thanks Cor.
What if user decides to cancel the thread middle of the process?


Set a Boolean variable that is checked by the thread and tells the
thread to stop processing.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7

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

Similar topics

5
by: Søren Reinke | last post by:
Hi there I am working on a program where the user should be able to import some CSV files. With my set of test data, it takes about 2 minutes to import, while it is importing the program sort...
0
by: King Tut | last post by:
I would like to display a progress bar (or some progress indication) when the user hits a submit button until the request is completed and is loaded.... Something that works like Flash, when you...
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: Jeff S | last post by:
I'm enabling users to upload files to the server. I'd like to show them some indication of percent complete. How can this be done? Thanks!
3
by: Ritesh Raj Sarraf | last post by:
Hi, I have a small application, written in Python, that uses threads. The application uses function foo() to download files from the web. As it reads data from the web server, it runs a progress...
8
by: WhiteWizard | last post by:
I guess it's my turn to ASK a question ;) Briefly my problem: I am developing a Windows app that has several User Controls. On one of these controls, I am copying/processing some rather large...
5
by: CCLeasing | last post by:
For an application I'm creating I want to create a 'fake' progress bar. By fake I mean a progress bar that looks like it's doing something but actually isn't. I know philosophically this isn't...
4
by: dgleeson3 | last post by:
Hello all Yes I know its been done before, but something silly is killing me on this. I have the standard progress bar and worker thread scenario with progress of the worker thread being fed...
5
dzenanz
by: dzenanz | last post by:
I have JSP web-form which uploads a file. In java code, I have a statement like this: for all lines in txt file uploaded call DB stored procedure As this web interface should be used over a...
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
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,...
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...
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.