timers and progress bar

G

Guest

Hi,

I am creating a project calls a function that has to run for a while. I
would like to display a progress bar on the bottom of that form while that
function is running but everything I've tried doesn't work. It seems like it
just wants to wait for that function to finish before it does anything else.
Any help that I can get would be appreciated.

Thanks
 
C

Cor Ligthert

BB,

I made this to test it and it is nicely running. Maybe can you try it
yourself.
I have set for this a statusbar on the form and on that a progressbar.

\\\
Private WithEvents tim As New Timer
Private Sub Form5_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
tim.Enabled = True
tim.Interval = 500
Me.ProgressBar1.Value = 1
Me.ProgressBar1.Step = 1
Me.ProgressBar1.Minimum = 1
Me.ProgressBar1.Maximum = 20
End Sub

Private Sub tim_Tick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tim.Tick
If ProgressBar1.Value <> ProgressBar1.Maximum Then
ProgressBar1.PerformStep()
Else
Me.Close()
End If
End Sub
///

Cor
 
H

Herfried K. Wagner [MVP]

bbdobuddy said:
I am creating a project calls a function that has to run for a while. I
would like to display a progress bar on the bottom of that form while that
function is running but everything I've tried doesn't work. It seems like
it
just wants to wait for that function to finish before it does anything
else.
Any help that I can get would be appreciated.

Run the function in a separate thread to prevent blocking the UI thread.

Some information on this topic (there's a link to a C# sample for writing a
multithreaded progress form on the bottom of the page):

Multithreading in Windows Forms applications
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top