vb.net scrolling a picture at same speed or same performance in 3 computers

WONG Tony 161 Reputation points
2021-09-10T14:02:13.257+00:00

i am designing a game with 3 computers to show a picture (1920 x 3000pixel at 1.4Mb size) scrolling on screen from top to bottom. My requirement is to require all computers to scroll to the bottom at the same time or 0.5 seconds difference between them.

firstly, i tried
do while until end of picture, thread sleep in loop to have scrolling effect
but the result is not satisfied. the difference between computers is up to 15 seconds

secondly, i tried
timer to scroll the picture until to the bottom
but the result is better but still not satisfied. the difference between computers is up to 6 seconds

any advice to do it? regardless of controlling scrolling speed, can i design in another way by scolling the picture within 40 seconds, the program control the speed by calculation.

Besides, i found when i run these kind of loop repeatedly. The result seems much better. the computer seems to adjust its CPU to run at full speed but my game does not run the loop repeatedly

Possible to set CPU speed by VB? Thanks a lot.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,629 questions
{count} votes

Accepted answer
  1. Viorel 113.8K Reputation points
    2021-09-12T17:44:27.58+00:00

    If you scroll the picture by adjusting its location, then try this code:

    Dim FinalTime = Now.AddSeconds(40)
    
    Dim t As New Thread(Sub()
    
                            Dim y As Double = Y1
    
                            Const dt = 20
                            While True
    
                                Dim iy = CInt(y)
    
                                Dim t1 = Now
    
                                PictureBox1.Invoke(Sub()
                                                        PictureBox1.Top = iy
                                                        PictureBox1.Update()
                                                    End Sub)
    
                                If iy = Y2 Then Exit While
    
                                Thread.Sleep(dt)
    
                                Dim dy = (Now - t1).TotalMilliseconds * (Y2 - y) / (FinalTime - Now).TotalMilliseconds
    
                                y += dy
                                y = Math.Min(Y2, y)
    
                            End While
    
                        End Sub)
    
    t.IsBackground = True
    t.Start()
    

    where Y1 is the initial vertical position, Y2 — the final vertical position of the picture (Y2 > Y1), 40 — the duration of the animation (seconds).

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. WONG Tony 161 Reputation points
    2021-09-15T11:38:30.953+00:00

    the 3 computers of same model can be completed at that time by adjusting process priority to high.

    amazingly, another older computer run faster than the 3 new computers

    Thanks all for teaching me

    0 comments No comments