I’m plotting a simple XY graph directly to the main window (not a canvas). The data has been captured via an external device and recorded at a predetermined sample rate (100Hz in this case).
As a useful feature, the user is able to replay the graph in real time. This all seems to work well except that occasionally whilst drawing the graph, the app hangs within the For/Next loop. By “hang” I mean I get the windows blue spinning circle and also the app window moves about 10pixels to the right and down, then moves back again - that bit is weird.
There doesn’t seem to be any regularity about it, but one thing that is consistent is that it hangs between 5-6 seconds into the draw. However, the method does actually end when it should. There are no active timers, so I don’t think it’s that. The code includes a point where the user can ESC the plotting which does still work, so the for/next loop does seem to be still running.
The issue occurs within the IDE and with a built version - so it’s not that.
The Code:
DrawGraphREPLAY
[code] // Get & set the delay number
timeCheckDelay = (1000000/deviceSampleRate) // convert
timeCheckOriginal = Microseconds
timeCheckAccumulator = timeCheckOriginal + timeCheckDelay
//-------graphing
For timeX as Integer = 0 to totalSamples-1
// -------------------------------------------------------------------
forceY = timeX
X1 = (timeX * standardGridX * graphScaleFactorX) + X1setPos
Y1 = (kGraphHeight - recordedGramsArray(forceY) * standardGridY * graphScaleFactorY) + Y1setPos
X2 = ((timeX+1) * standardGridX * graphScaleFactorX) + X2setPos
Y2 = (kGraphHeight - recordedGramsArray(forceY+1) * standardGridY * graphScaleFactorY) + Y2setPos
//Draw the final graph lines
Graphics.Transparency = 25 // overlay on paper image background
Graphics.DrawLine(X1, Y1, X2, Y2)
// Force Exit Replay if Mouse is out of bounds
If MouseX < 220 OR MouseY < 40 OR MouseX > 1000 OR MouseY > 550 Then // Mouse Bounds Invalid
MsgBox ("Mouse out of range")
WindowMain.RefreshRect (295,89,668,408)
Return
End If
// Allow Exit Replay on ESC key
If Keyboard.AsyncKeyDown(&h35) Then // ESC
MsgBox ("You have forced Replay to end.")
WindowMain.RefreshRect (295,89,668,408)
Return
End If
ReplayDELAY // check & delay until correct
Next timeX[/code]
At the end of the for/next loop the delay is called.
ReplayDELAY
[code] timeCheckOriginal = Microseconds
While timeCheckOriginal < timeCheckAccumulator
timeCheckOriginal = Microseconds
Wend
timeCheckAccumulator = timeCheckAccumulator + timeCheckDelay[/code]
The logic part of the code to draw the graph may look messy, but it works fine so it’s not that. Also the timing is spot on.
If it was consistent then I could track it down.
Hopefully someone will see something that I’ve missed.
Cheers.
2016R3 Win7