Solved

Getting the Timer to start

Posted on 2009-04-02
5
223 Views
Last Modified: 2012-05-06
I setup a Timer and start it with all the instructions I know of.  However, it does not go to the Timer procedure until after what I am trying to time has finished.

My code:

PRIVATE SUB
        ' I START THE TIMER
        Timer_Progress.Interval = 1000
        Timer_Progress.Enabled = True
        Timer_Progress.Start()

        ' I TURN ON MY PROGRESS BAR
        ProgressBar1.Value = 0
        ProgressBar1.BackColor = Color.Goldenrod
        ProgressBar1.ForeColor = Color.Gold
        ProgressBar1.Visible = True

       more code
       .
       .    
        Timer_Progress.Enabled = False
END SUB

AS IT CYCLES THRU MY CODE I WANT THE BELOW PROCEDURE TO EXECUTE TO ADVANCE MY PROGRESS BAR, BUT IT ONLY GOES THERE AFTER THE ENTIRE ABOVE CODE HAS FINISHED.

 Private Sub Timer_Progress_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_Progress.Tick
        ProgressBar1.Value = ProgressBar1.Value + 5
    End Sub

Any ideas?
0
Comment
Question by:GarySB
5 Comments
 
LVL 7

Expert Comment

by:cmrobertson
Comment Utility
try reordering the timer command to enable it before setting the interval and start
0
 
LVL 48

Expert Comment

by:jpaulino
Comment Utility
For that you don't need a timer, you only have to do your increments in the sub, like:
ProgressBar1.Value = 0
ProgressBar1.BackColor = Color.Goldenrod
ProgressBar1.ForeColor = Color.Gold
ProgressBar1.Visible = True
'  some code
ProgressBar1.Value  = 10
' other code
ProgressBar1.Value = 20
' more code
ProgressBar1.Value = 30
 
etc
 
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 100 total points
Comment Utility
"BUT IT ONLY GOES THERE AFTER THE ENTIRE ABOVE CODE HAS FINISHED."

The code is "stuck" in the Sub...you need to call Application.DoEvents() periodically in your code to allow the Tick() events to be processed.

The same would hold true for jpaulino's suggestion.  Call Application.DoEvents() after each update to allow the GUI controls to repaint themselves.

If you have VB.Net 2005 (or above) then use the BackgroundWorker() control instead:
http://msdn.microsoft.com/en-us/library/c8dcext2(vs.80).aspx
0
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 25 total points
Comment Utility
Forgot the Application.DoEvents() after set the value but you can use that or ProgressBar1.Update()
Thanks for the correction Idle :)
0
 

Author Closing Comment

by:GarySB
Comment Utility
I had ProgressBar1.Value  = 10, 20 etc., but dealing with Forms copying hung it up.
Appreciate your help.  Reordering Enable command did not change.
Placing  Application.DoEvents() worked, but had to place it all thru code.
I increment 5 and this fills in the remaining gap at the end of procedure
        Do Until ProgressBar1.Value = 100
            Application.DoEvents()
        Loop
Thank You Genius's
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now