form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter
Go Back  Xtreme Visual Basic Talk > > > form lockup using QueryPerformanceCounter


Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2013, 12:41 AM
graham2550 graham2550 is offline
Newcomer
 
Join Date: Aug 2013
Posts: 11
Unhappy form lockup using QueryPerformanceCounter


I am creating a Kw/Hr meter, similar to what you find in your meter box as part of a larger project,I am moving a bitmap of the numbers(0-9) up in pictureboxs, 1 pix at a time. 25 pix per number. The fastest the right hand image has to increment is about 40 steps a second (20mS). I am using QueryPerformanceCounter and QueryPerformanceFrequency to create a delay.
My problem is I get a stack overflow, which I can turn off. But when I try to move the form when running it freezes my machine, but not the program, keeps running.
If I run it in a thread I instantly get an exception, object in use elsewhere. this is the graphics object.
Anyone ideas?? Please

Code:
Imports System.IO.Ports
Imports System.Text
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Graphics
Imports System.Threading

Public Class Form1
	Dim Watts_This_period As Single = 45000	'this is set for testing only, normally would come from main program
	Dim gr As Graphics
	Private pbKW() As PictureBox			'pictureboxes 25 x 25 pix
	Dim bmKW(5) As Bitmap					'holds each image 
	Dim KWcounter(5) As Integer				'to track position of image in picturebox

	Dim cTimer As Long						'used in query performance counter
	Dim cTimer2 As Long
	Dim Freq As Long
	Dim DataThread As New Threading.Thread(AddressOf start)
	Declare Function QueryPerformanceCounter Lib "kernel32" (ByRef counts As Long) As Integer
	Declare Function QueryPerformanceFrequency Lib "kernel32" (ByRef frequency As Long) As Integer

	Public Sub New()
		InitializeComponent()
		pbKW = New PictureBox() {pb100ths, pb10ths, pb1s, pb10s, pb100s, pb1000s}	'small pictureboxes
	End Sub

	Private Sub updateBoxes(ByVal z As Integer)

		Application.DoEvents()
		Using gr As Graphics = Graphics.FromImage(bmKW(z))					'get the graphics object
			gr.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
			gr.DrawImage(PictureBox1.Image, 0, KWcounter(z))				'put in pb at next position
		End Using
		pbKW(z).Image = bmKW(z)												'copy to the pb
		KWcounter(z) = KWcounter(z) + 1
		'increment
		If KWcounter(z) = 0 Then KWcounter(z) = -250 'if at top go back to bottom
		If KWcounter(z) > -26 And KWcounter(z) < 0 Then						'if at 9 start to roll the next pb
			z = z + 1
			updateBoxes(z)
		End If

	End Sub

	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
		Dim i As Integer
		For i = 0 To 5
			KWcounter(i) = -250										'set all counters
			bmKW(i) = New Bitmap(25, 275)							'initiate all bmps
		Next
		Using gr As Graphics = Graphics.FromImage(bmKW(0))
			gr.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
			gr.DrawImage(PictureBox1.Image, 0, -250)				'get the graphics object from hidden picturebox1 (25 x 275)
		End Using
		For i = 0 To 5
			pbKW(i).Image = bmKW(0)									'copy picture to all the pictureboxes
		Next
		QueryPerformanceFrequency(Freq)								'get frequency
		Label1.Text = Now											'for testing timing only

	End Sub

	Private Sub start()
		Dim delay As Long = 3600000000 / (2.5 * Watts_This_period)	'calculate the stepping delay 
		Do
			Application.DoEvents()
			Pause(delay)				'this is microseconds delay   
			updateBoxes(0)				'move the meter
		Loop
		'DataThread.Abort()
	End Sub

	Private Sub Pause(HowLong As Long) 'Function for pause in microseconds

		QueryPerformanceCounter(cTimer)	   'get first time
		Do
			QueryPerformanceCounter(cTimer2) 'get second time
		Loop Until cTimer2 > cTimer + (Freq / (1000000 / HowLong)) 'do till delay , make 1000 for milliseconds

	End Sub

	Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

		'Dim DataThread As New Threading.Thread(AddressOf start)		'get a thread to do the graph
		'DataThread.Priority = ThreadPriority.Normal
		'DataThread.IsBackground = True
		'DataThread.Start()
		start()	'comment this if using threading
	End Sub

End Class

Last edited by Flyguy; 08-15-2013 at 02:35 AM. Reason: Added [code][/code] tags
Reply With Quote
  #2  
Old 08-15-2013, 07:17 AM
PlausiblyDamp's Avatar
PlausiblyDampform lockup using QueryPerformanceCounter PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

If you are using threading then you don't want to be calling Application.DoEvents from a background thread anyway, also updating the UI from anything other than the main thread is another big no no.

If you with to use a thread to update things then you will need to communicate with the main UI thread for the actual drawing.

In all honesty you might find using WPF to be a much easier solution if you are trying to do high performance graphics as winforms isn't really designed for this kind of thing.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 08-15-2013, 08:46 AM
passel's Avatar
passelform lockup using QueryPerformanceCounter passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

For displaying instrumentation I think trying to use QueryPerformance... API functions is overkill, and running an idle delay loop is a big energy drain.
The simplest approach is just use a timer and set it to the shortest tick time. The actual tick period will vary so you wouldn't want to make elapsed time calculations based on how many ticks have gone by, but by referencing a time source to see how much time has passed.
If you pick the shorted time period, 1ms, the timer will probably fire at least every 15.625 ms (64 hz) as a minimum. Some machines Winform's timers will tick faster, but they are getting rarer.
Since 64 hz is faster than you need, it should suit your purpose. Since it won't always be 64 hz (your drawing might cause it to drop to 32 hz or less sometimes) you will need to check the independent timing source to see how much time has actually passed.
I usually like to use a Stopwatch object and check the elapsed milliseconds.
You would see how much time has passed, multiply by the rate you want to move the image per millisecond, and redraw.
All your drawing would be done in the GUI thread, so no issues with cross threading access, and it would look fine without sucking all the processing power of the machine to try to do exacting time measurements.

If you really do want to isolate the timing and drawing, etc. to a separate thread, you can do that by directly updating the screen area "over" a control using a BufferedGraphics object to render the image. While you can't update a GUI control from a separate thread, you can update the Screen from a separate thread.

But, I would give the first option a try to see how you like it. It is just a little change in the mindset. Instead of trying to precisely time the movement of 40hz to move 1 pixel (and that is not a good option since depending on power demand, that 1 pixel movement at 40 hz is the maximum rate, not a fixed rate), it makes more sense to determine how far each digit should move per millisecond based on the current power drawn, and how much time has elapsed (in milliseconds), and move the digits that amount (elapsed ms * distance per ms). Much easier to calculate and much easier to draw considering both power and time intervals between drawing updates will vary.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #4  
Old 08-15-2013, 09:05 PM
graham2550 graham2550 is offline
Newcomer
 
Join Date: Aug 2013
Posts: 11
Default QueryPerformanceCounter

Thanks for your reply Passel, I will try again with the stopwatch and dump the QueryPerformanceCounter idea. I also don't like using threading, always gives me problems.
I agree the time set is not necessarily the time taken, but you have made it more obvious to me. I started to use QueryPerformanceCounter because I needed sub miilisecond accuracy. i.e. 23.45 mS. as you can imagine that .45 mS (which gets chopped off in a timer) can make a large difference over a few minutes let alone a few months.
Can you give me some pointers on using the stopwatch in my scenario, if possible, I have already played around with the stopwatch but couldn't figure out how to use it in this case.
Reply With Quote
  #5  
Old 08-16-2013, 11:53 AM
Cerian Knight's Avatar
Cerian Knightform lockup using QueryPerformanceCounter Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,199
Default

Not sure this is an issue in .NET, but QPF/QPC would ByVal the argument using the code in post #1 (with parens) under VB6 when not returning a function success value... which would probably endlessly loop.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').

Last edited by Cerian Knight; 08-16-2013 at 12:02 PM.
Reply With Quote
  #6  
Old 08-16-2013, 01:42 PM
passel's Avatar
passelform lockup using QueryPerformanceCounter passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

Using the stopwatch might not get you true sub-millisecond accuracy, although ticks are available, but rather allow you to check for the passage of time without accumlating errors. By allowing the stopwatch to run continuously and taking snapshots of the time as it passes should allow you to calculate values without losing or gaining time based on an assumed program cycling rate.
So, rather than explain in detail, a quick example attached.

You start a stopwatch to track time, and you start a timer to give you periodic events to process and update the display.
It just has a trackbar at the top where you can vary the rate from 0 to the maximum 40 pixels per second (40hz) you specified.
It will scroll a single digit so you can see it update the display, as well as update a label with a representation of the accumulated value.

p.s. Looking back to the first post I see you had 25x25 pixel size for the digits. I meant mine to be the same as yours, but didn't look back at the post when I wrote the example and I thought you had 32x32.

Code:
Public Class Form1
  Dim runTime As New Stopwatch                              'To track passing time accurately, I assume
  Dim lastTime As Long                                      'To compute time from the previous cycle
  Dim PixelPerMillisecond As Double                         'The rate of movement of the digit in pixelsPerMillisecond
  Dim totalKwatts As Double                                 'Accumlation of power used in 1/32nds of a unit (to match our pixels per unit)
  Dim digitPosition As Integer                              'Computed offset in the digitstrip to display from
  Dim digitImages As New Bitmap(My.Resources.numstrip)      'Our source image with the digits 0 to 9
  Dim destRect As New Rectangle(0, 0, 32, 32)               'We copy a portion of the digit map to this location (doesn't change)
  Dim srcRect As New Rectangle(0, 0, 32, 32)                'Where we copy from, the Y value will change to select the portion

  Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    TrackBar1.Value = 400                                  'Default to have some movement, at our maximum
    PixelPerMillisecond = 400 / 10000                      'Set the PixelPerMillisecond to match

    runTime.Start()         'Start the stopwatch
    Timer1.Interval = 1     'Get periodic tics from the Timer at whatever the fastest speed it can do, won't be near 1 most likely
    Timer1.Start()          'Start our periodic timer
  End Sub

  Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    Dim thisTime As Long = runTime.ElapsedMilliseconds    'Snapshot the current elapased time from the stopwatch
    Dim deltaTime As Long = thisTime - lastTime           'Subtract the previous snapshot to see how much time has passed
    lastTime = thisTime                                   'Save the current elapsed time for the next cycle
    ComputePowerUsage(deltaTime)                          'Pass the elapsed time to the power usage computation
  End Sub

  Private Sub ComputePowerUsage(dTim As Long)
    totalKwatts += PixelPerMillisecond * dTim         'Accumlate the usage
    digitPosition = 336 - (Int(totalKwatts) Mod 320)  'Determine where in our digit map we are based on the usage
    If digitPosition < 16 Then                        'zero is 16 pixels from the bottom of the bitmap, 
      digitPosition += 320                            '  wrap back to the top, to another zero for seemless scrolling
    End If
    Label1.Text = (totalKwatts / 32000).ToString("0.000")
    PictureBox1.Invalidate()     'Invalidate the Picturebox so it will redraw itself
  End Sub

  Private Sub TrackBar1_Scroll(sender As System.Object, e As System.EventArgs) Handles TrackBar1.Scroll
    'Trackbar maximum set to 400, (400/10000) = .04 pixel per ms, which is 40 pixels per second max rate
    PixelPerMillisecond = TrackBar1.Value / 10000
  End Sub

  Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    srcRect.Y = digitPosition    'Modify the source rectangle to select the current position
    e.Graphics.DrawImage(digitImages, destRect, srcRect, GraphicsUnit.Pixel)  'and draw it
  End Sub
End Class
Attached Files
File Type: zip QuickOdometerExample.zip (21.0 KB, 2 views)
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 08-16-2013 at 01:51 PM.
Reply With Quote
  #7  
Old 08-22-2013, 03:59 AM
graham2550 graham2550 is offline
Newcomer
 
Join Date: Aug 2013
Posts: 11
Default

Hi Passel,
sorry for my late reply, had to go down to Bangkok, personal matter.
Anyway this looks very promising and I can see you spent considerable time on this for me. Thanks.
I'll let you know how I get on.
Thanks to all for your replies.
Reply With Quote
  #8  
Old 08-25-2013, 10:54 PM
graham2550 graham2550 is offline
Newcomer
 
Join Date: Aug 2013
Posts: 11
Default scrolling meter

Hi Passel,
This worked fantastic, thankyou so much. you're a legend
The only thing I cant get right is scrolling effect of the digit to the left when it gets to 9, at the moment it just changes, 1, 2, 3 etc
I would like that when a digit gets to 9, the digit to its left would scroll to the next number. its probably only 1 or 2 lines of code! But i've tried and tried with success
code below
Code:
Public Class Form1
  Dim runTime As New Stopwatch            'To track passing time accurately, I assume
  Dim lastTime As Long                    'To compute time from the previous cycle
  Dim PixelPerMillisecond As Double       'The rate of movement of the digit in pixelsPerMillisecond
  Dim totalKwatts As Double               'Accumlation of power used in 1/32nds of a unit (to match our pixels per unit)
  Dim digitPosition(6) As Integer         'Computed offset in the digitstrip to display from
  Dim KWThisPeriod As Integer = 40000     'set for testing only ******************
  Dim Div(5) As Integer                   'divider array
  Dim inc As UShort                       'loop incrementer
  Dim digitImages As New Bitmap(My.Resources.numstrip3) 'Our source image with the digits 0 to 9

  Dim destRect As New Rectangle(0, 0, 25, 30) 'We copy a portion of the digit map to this location (doesn't change)
  Dim srcRect As New Rectangle(0, 0, 25, 30)  'Where we copy from, the Y value will change to select the portion
  Dim pbKW() As PictureBox                'pictureboxes 25 x 25 pix

  Public Sub New()
    InitializeComponent()
    pbKW = New PictureBox() {PictureBox1, PictureBox2, PictureBox3, _
                             PictureBox4, PictureBox5, PictureBox6, PictureBox7} 'small pictureboxes
  End Sub

  Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    For inc = 0 To 6                  'init the pictureboxes
      digitPosition(inc) = 261
    Next
    Div(0) = 10                       'set the dividers
    For inc = 1 To 5
      Div(inc) = Div(inc - 1) * 10
    Next
    PixelPerMillisecond = KWThisPeriod / 1800000 * 1.25   'start the ball rolling as 1 second timer comes in late
    Label3.Text = Now     'for testing only
    runTime.Start()       'Start the stopwatch
    Timer1.Interval = 1   'Get periodic tics from the Timer at whatever the fastest speed it can do, won't be near 1 most likely
    Timer1.Start()        'Start our periodic timer
  End Sub

  Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    Dim thisTime As Long = runTime.ElapsedMilliseconds    'Snapshot the current elapased time from the stopwatch
    Dim deltaTime As Long = thisTime - lastTime           'Subtract the previous snapshot to see how much time has passed
    lastTime = thisTime                                   'Save the current elapsed time for the next cycle
    ComputePowerUsage(deltaTime)                          'Pass the elapsed time to the power usage computation
  End Sub

  Private Sub ComputePowerUsage(dTim As Long)
    totalKwatts += PixelPerMillisecond * dTim       'Accumlate the usage
    digitPosition(0) = 261 - (Int(totalKwatts) Mod 250)   'Determine where in our digit map we are based on the usage
    pbKW(0).Invalidate()                  'Invalidate the Picturebox so it will redraw itself
    For inc = 0 To 5
      If digitPosition(inc) < 14 Then           'zero is 14 pixels from the bottom of the bitmap, 
        digitPosition(inc) += 250           'wrap back to the top, to another zero for seemless scrolling
        digitPosition(inc + 1) = 261 - (Int(totalKwatts / Div(inc)) Mod 250)  'and scroll the next digit 
        pbKW(inc + 1).Invalidate()            'invalidate the next digit pb
        If digitPosition(6) < 14 Then         'if we are at 99999.99 then reset everything
          digitPosition(6) += 250
          pbKW(6).Invalidate()
          totalKwatts = 0
        End If
      End If
    Next
    Label1.Text = (totalKwatts / 2500).ToString("00000.00") 'for testing only****************
  End Sub

  Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    srcRect.Y = digitPosition(0)    'Modify the source rectangle to select the current position
    e.Graphics.DrawImage(digitImages, destRect, srcRect, GraphicsUnit.Pixel)  'and draw it
  End Sub

  Private Sub PictureBox2_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox2.Paint
    srcRect.Y = digitPosition(1)   'Modify the source rectangle to select the current position
    e.Graphics.DrawImage(digitImages, destRect, srcRect, GraphicsUnit.Pixel)  'and draw it
  End Sub
  Private Sub PictureBox3_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox3.Paint
    srcRect.Y = digitPosition(2)   'Modify the source rectangle to select the current position
    e.Graphics.DrawImage(digitImages, destRect, srcRect, GraphicsUnit.Pixel)  'and draw it
  End Sub
  Private Sub PictureBox4_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox4.Paint
    srcRect.Y = digitPosition(3)   'Modify the source rectangle to select the current position
    e.Graphics.DrawImage(digitImages, destRect, srcRect, GraphicsUnit.Pixel)  'and draw it
  End Sub
  Private Sub PictureBox5_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox5.Paint
    srcRect.Y = digitPosition(4)  'Modify the source rectangle to select the current position
    e.Graphics.DrawImage(digitImages, destRect, srcRect, GraphicsUnit.Pixel)  'and draw it
  End Sub
  Private Sub PictureBox6_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox6.Paint
    srcRect.Y = digitPosition(5)  'Modify the source rectangle to select the current position
    e.Graphics.DrawImage(digitImages, destRect, srcRect, GraphicsUnit.Pixel)  'and draw it
  End Sub
  Private Sub PictureBox7_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox7.Paint
    srcRect.Y = digitPosition(6)   'Modify the source rectangle to select the current position
    e.Graphics.DrawImage(digitImages, destRect, srcRect, GraphicsUnit.Pixel)  'and draw it
  End Sub
  Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    PixelPerMillisecond = KWThisPeriod / 1800000 * 1.25 'Kilowatts this period at 2 second interval,normally comes from main program
  End Sub
End Class
Attached Files
File Type: zip QuickOdometerExample.zip (40.4 KB, 2 views)

Last edited by passel; 09-06-2013 at 08:51 PM. Reason: Added code tags, reformatted to reduce window width
Reply With Quote
  #9  
Old 09-06-2013, 08:56 PM
passel's Avatar
passelform lockup using QueryPerformanceCounter passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

I've been busy at work and somehow missed the update to this thread until today.
A small change to your code to pull the two line that adjust the next digit out of the "0" wrap block and into a "passing 9" block.
Then use the offset of the current digit, with some bias, to your calculation of the next digits position so it scrolls along with the 9 to 0 movement of the current digit.
This should be pretty close to what you want.
Code:
  Private Sub ComputePowerUsage(dTim As Long)
    totalKwatts += PixelPerMillisecond * dTim       'Accumlate the usage
    digitPosition(0) = 261 - (Int(totalKwatts) Mod 250)   'Determine where in our digit map we are based on the usage
    pbKW(0).Invalidate()                  'Invalidate the Picturebox so it will redraw itself
    For inc = 0 To 5
      If digitPosition(inc) < 35 Then
        digitPosition(inc + 1) = 250 + digitPosition(inc) - (Int(totalKwatts / Div(inc)) Mod 250)  'and scroll the next digit 
        pbKW(inc + 1).Invalidate()            'invalidate the next digit pb
      End If
      If digitPosition(inc) < 14 Then           'zero is 14 pixels from the bottom of the bitmap, 
        digitPosition(inc) += 250           'wrap back to the top, to another zero for seemless scrolling
        If digitPosition(6) < 14 Then         'if we are at 99999.99 then reset everything
          digitPosition(6) += 250
          pbKW(6).Invalidate()
          totalKwatts = 0
        End If
      End If
    Next
    Label1.Text = (totalKwatts / 2500).ToString("00000.00") 'for testing only****************
  End Sub
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #10  
Old 09-10-2013, 06:37 AM
graham2550 graham2550 is offline
Newcomer
 
Join Date: Aug 2013
Posts: 11
Talking kilowatt meter

thankyou so much for your help Passel, this worked a treat.
I think I can safely say this problem is now solved.
anyone that needs a good meter, for whatever, use the code of mine above with Passels latest modifications.
Reply With Quote
  #11  
Old 09-10-2013, 10:45 AM
passel's Avatar
passelform lockup using QueryPerformanceCounter passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

I think since the rate is a float and the trigger (< 14) is an integer, a given digit might end up resting at a given spot, plus or minus a pixel, and that random difference might proprogate itself up the line of images, so you could have digits settle at random spots a number of pixels off.
It does make the display appear a bit more "mechanical" since the digits don't always line up precisely with one another across the readout, but you might want to add back the two lines you had in the "< 14" block to "snap" the digit+1 position to its final desired position.

I think you may also have an issue if you pause the program for a length of time since the code kind of depends on the rolling over of one digit feeding into the next.
I haven't tested it, but I think if there was a jump in elapsed time (from pausing the program, or trying to set the value to an initial value then some digits will be incorrect, until enough time has passed to cause all digits to have been recalculated because of roll over of the previous digit.

The code should probably be changed so that each digits position could be calculated from the current value, rather than rely on the scrolling position of the previous digit to cause it to be computed.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #12  
Old 09-18-2013, 11:35 PM
graham2550 graham2550 is offline
Newcomer
 
Join Date: Aug 2013
Posts: 11
Cool Kilowatt meter

Hi Passel,
sorry for late reply, just noticed this reply from you.
Yes, point noted. Integers round up and down so I'm thinking that if this does happen then it will average itself out in the end.
However having said that I will keep an eye on it. It has been running for several hours without a hitch and I am very happy with this. I did have to change the 250 to 249, the digit was over shooting.
I will add in some code to ensure each digit when it scrolls will be at the correct position just to be sure.
Thanks again for all your help.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter
 
form lockup using QueryPerformanceCounter
form lockup using QueryPerformanceCounter
 
-->