Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting the Timer to start

Posted on 2009-04-02
5
Medium Priority
?
231 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 400 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 100 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

610 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