Solved

Getting the Timer to start

Posted on 2009-04-02
5
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 7

Expert Comment

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

Expert Comment

by:jpaulino
ID: 24051284
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 86

Accepted Solution

by:
Mike Tomlinson earned 100 total points
ID: 24051628
"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
ID: 24051758
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
ID: 31565848
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 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