• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

Recording correct time for routine to run

vb.net 2003 sp4
I have a routine that takes a while to run sometimes.
its posts the time on a form as it runs.

It seems as if if the screen saver kicks in its throws off the time..
or could just be bad code..?


I cannot make



public sub Routine()
Dim startDT As DateTime = DateTime.Now
....
' update form
        Me.Label17.Text = startDT
code


' finish it up
        Dim endDT As DateTime = DateTime.Now
        Dim elapsed As TimeSpan = endDT.Subtract(startDT)
        Dim strEnd As String
        strEnd = "Project Completed In: "
        Label17.Text = strEnd & elapsed.Minutes & " mins " & elapsed.Seconds & " secs"
        Me.Label17.Refresh()

end sub


Thanks
fordraiders
0
Fordraiders
Asked:
Fordraiders
  • 5
  • 3
  • 2
1 Solution
 
DabasCommented:
What exactly do you mean by "It seems as if if the screen saver kicks in its throws off the time.."

Code looks OK. What exactly the problem is, is not clear.

Dabas
0
 
FordraidersAuthor Commented:
I know the programs runs at least 1-1/2 but it says at the end of the orutine.. 8min 30secs?

The screen saver is just a wild guess as to what the problem is..
0
 
DabasCommented:
I have tested on my system, and it seems to work OK.

Try one or more of the following: Turning your screen saver off
Running the routine on another computer
Check your code that you are not changing the value of startDT anywhere
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Bob LearnedCommented:
I would think that you would need something like a Stopwatch:

Dim watch As New Stopwatch()
watch.Start()

...

watch.Stop()
0
 
FordraidersAuthor Commented:
do I set a variable to read the start and stop of the watch ?

dim stSartWatch as datetime ?

0
 
Bob LearnedCommented:
Better example:


        Dim watch As New Stopwatch()
        watch.Start()
 
        ' Do something
 
        watch.Stop()
 
        Dim totalSeconds As Double = watch.Elapsed.TotalSeconds

Open in new window

0
 
FordraidersAuthor Commented:
Cao, Do i need to decalre any special "Imports"
0
 
FordraidersAuthor Commented:
Cap , Something I just thought of... If the timer goes beyond 1 hour...does it reset and still just give me the minutes past one hour duration ?


so if I ran... 1hour 5 min 25 sec

I'm only telling it to bring me back min and secs ?


0
 
Bob LearnedCommented:
The Stopwatch is in the System.Diagnostics namespace.  The timer covers the same time period as a TimeSpan, since that what the Elapsed property is.  It will not reset after an hour.  

1 hour 5 min 25 sec = 3925 seconds.

Since Elapsed is a TimeSpan instance, there are other properties associated with it, like Hours, Minutes, Seconds, etc.
0
 
FordraidersAuthor Commented:
Working good now...Thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now