Solved

Getting the Timer to start

Posted on 2009-04-02
5
227 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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