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

Using threading to provide ProgressBar

Rather than putting a progress bar on all of my forms to show progress during time consuming tasks, I made a form called frmProgress with 2 controls, a Label and a ProgressBar. Suppose I expose 1 property -- prgValue (the Value of the ProgressBar); how do I use threading so that my time consuming task will open and display frmProgress as well as continually update prgValue (and display its progress), and then close frmProgress upon completion? This seems a pretty mundane thing to do. Is there an example somewhere

Thanks.
Nov 20 '05 #1
4 4742
* "=?Utf-8?B?cG1jZ3VpcmU=?=" <an*******@discussions.microsoft.com> scripsit:
Rather than putting a progress bar on all of my forms to show progress
during time consuming tasks, I made a form called frmProgress with 2
controls, a Label and a ProgressBar. Suppose I expose 1 property --
prgValue (the Value of the ProgressBar); how do I use threading so that
my time consuming task will open and display frmProgress as well as
continually update prgValue (and display its progress), and then close
frmProgress upon completion? This seems a pretty mundane thing to do.
Is there an example somewhere?


In C#:

<http://www.codeproject.com/cs/miscctrl/progressdialog.asp>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Cor
Hi,

I thought Armin would send his sample himself.

This Armin made a while ago.

\\\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
///
I hope this helps a little bit?

Cor
Rather than putting a progress bar on all of my forms to show progress during time consuming tasks, I made a form called frmProgress with 2
controls, a Label and a ProgressBar. Suppose I expose 1 property --
prgValue (the Value of the ProgressBar); how do I use threading so that my
time consuming task will open and display frmProgress as well as continually
update prgValue (and display its progress), and then close frmProgress upon
completion? This seems a pretty mundane thing to do. Is there an example
somewhere?
Thanks.

Nov 20 '05 #3
"Cor" <no*@non.com> schrieb
Hi,

I thought Armin would send his sample himself.

This Armin made a while ago.

Thx :)
--
Armin

Nov 20 '05 #4
"pmcguire" <an*******@discussions.microsoft.com> schrieb
[...]


Either it's too late for me now (1:40 am) or you put the work in the wrong
thread. If you wanna do something in the background you should put it in
"Sub ThreadStart". A basic rule is that a control must only be accessed in
the same thread that created the control. The code looks as if your main
target is to fill a Treeview. This is usually not done in the background
(but it can be), so IMO it does not make much sense to put it in a separate
thread. If you did, you would have to use the control's Invoke or
BeginInvoke method within the other thread. These two methods call a
procedure in the same thread that created the control (see docs). Within the
called procedure, you can acces the control without a problem. In your case
I would fill the treeview and update the progressbar in the same thread. It
would slow down filling the Treeview considerably if the largest part was
marshalling the work to the main thread, so you'd better keep it there right
from the start.

A "better" situation, for example, would be processing a volume on the disc
in a separate thread and filling a listview with the result each time an
item is found.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5

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

Similar topics

17
by: Arun Kumar | last post by:
What is wrong with this code. All i am trying to test is 3 progressbar and one button. On buttonclick i create 3 threads and each thread calls a method which in turn updates the progressbar and it...
2
by: Vjay77 | last post by:
In this code: Private Sub downloadBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Not (Me.downloadUrlTextBox.Text = "") Then Me.outputGroupBox.Enabled = True...
0
by: Ban Leong | last post by:
Hi all... I am developing a simple program to transfer file from desktop to ppc using OpenNetCF.Desktop.Communication class. I want to show a progress bar indicating the file is being...
1
by: Tim Ryter | last post by:
Greetings, Please excuse my newbieness up front, I am very new to developing complex applications, and am finding myself banging my head against the desk regularly. :) What I am basically...
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...
2
by: lewisms | last post by:
Hello all, I am quite new to c++/. Net so please don't shoot me down for being a newbie. Any way I am trying to make a simple multithreading program that is just to learn the ideas behind it...
7
by: kimiraikkonen | last post by:
Hello experts, I've been already working on a project and also asked and i've managed to create a basic Gmail mail sender, but i want to add a progressbar that shows "sending is in progress" but...
2
by: vijayrvs | last post by:
SearchCrawler.java The program search crawler used to search the files from the website. From the following program i got 7 compiler error. can any body clarify it and provide me solution. ...
1
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
Hi all I have a question about threading with forms. On my form I have a Progressbar and a Timer for updating it. On the timer update I call Invoke and this works fine. When it runs, the form...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
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...

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.