Why does timer code (by dbasnett) no longer work splendidly?

Using timer code supplied by dbasnett back in May2014, I was able to see FPS of near 500 for a simple animation. Now, with a more recent 64bit laptop Win 8.1 - -  I run the same code - - - and see poor results similar to standard timers - - where the
results are "stepped" - - -like either 16FPS or 32FPS or the max I can get is 64FPS.
This thread back in May2014  - -https://social.msdn.microsoft.com/Forums/vstudio/en-US/9ddb2f16-796a-483a-aa3f-0f9b959e0eea/the-use-of-systemwindowsformstimer-for-time?forum=vbgeneral
And here is the code that dbasnett supplied - -
Public Class Form1
Dim R As Integer
Dim D, T As Double
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.ClientSize = New Size(500, 500)
Me.DoubleBuffered = True
T = Environment.TickCount
timeSubThrd = New Threading.Thread(AddressOf timeSub)
timeSubThrd.IsBackground = True
timeSubThrd.Start()
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
If Not slp.WaitOne(0) Then
'RemoveHandler Me.Paint, AddressOf Me.Form1_Paint
slp.Set()
e.Cancel = True
End If
End Sub
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim rct As Rectangle = New Rectangle(250 - R, 250 - R, 2 * R, 2 * R)
Using spen As New Pen(Color.FromArgb(83, 32, 69))
spen.Width = 4
e.Graphics.DrawEllipse(spen, rct)
End Using
End Sub
Dim timeSubThrd As Threading.Thread
Dim slp As New Threading.ManualResetEvent(False)
Private Sub timeSub()
Dim A As Double = -1
Do
D += 0.125663707
If D > (2 * Math.PI) Then
A = 50000 / (Environment.TickCount - T)
T = Environment.TickCount
D = 0
End If
R = CInt(Math.Cos(D) * 60) + 180
Me.Invoke(Sub()
Invalidate()
If A <> -1 Then
Me.Text = A.ToString("##0.0##") & " FPS"
End If
End Sub)
A = -1
Loop While Not slp.WaitOne(20) '<<<<<<< the timer interval
Me.Invoke(Sub()
Me.Close()
End Sub)
End Sub
End Class
With timer interval set to 20 - - - - it used to give about 50FPS (which is should), but it doesnt anymore - - - it gives 32FPS.
Can anybody shed some light on what has gone wrong? My present laptop also a I7 is 4 years younger than my old laptop and has far betters specs. Why is it slower? or why is this timer code no longer acting the same?
Thanks
Leon Stanley - ♪Don't pay the ferryman - till he gets you over to the other side♪ . um . I apply this to corporations - not to God.

@ Reed Kimble. Thanks for your point about not being OS related. That make sense anyway.
@ Mr.Monkeyboy. Thanks for your links and points. I had a bit of a read. Mostly over my head. To me it should'nt be a thread priority question because the program is so simple - there is only one thread anyway.
And I don't think it is a graphics issue, because I altered the program to only manipulate a bitmap - not activate a paint event -  - - but it still performs poorly. I only get 32 Cycles Per Second instead of 50 CPS. See - this is how I altered the
code - but no change in performance:-
Public Class Form4
Dim bmp As Bitmap
Dim gfx As Graphics
Dim R As Integer
Dim D, T As Double
Private Sub Form4_Load(sender As Object, e As System.EventArgs) Handles Me.Load
bmp = New Bitmap(500, 500)
gfx = Graphics.FromImage(bmp)
Me.ClientSize = New Size(500, 500)
T = Environment.TickCount
timeSubThrd = New Threading.Thread(AddressOf timeSub)
timeSubThrd.IsBackground = True
timeSubThrd.Start()
End Sub
Private Sub Form2_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
If Not slp.WaitOne(0) Then
'RemoveHandler Me.Paint, AddressOf Me.Form2_Paint
slp.Set()
e.Cancel = True
End If
End Sub
Sub test()
Dim rct As Rectangle = New Rectangle(250 - R, 250 - R, 2 * R, 2 * R)
Using spen As New Pen(Color.FromArgb(83, 32, 69))
spen.Width = 4
gfx.DrawEllipse(spen, rct)
End Using
End Sub
Dim timeSubThrd As Threading.Thread
Dim slp As New Threading.ManualResetEvent(False)
Private Sub timeSub()
Dim A As Double = -1
Do
D += 0.125663707
If D > (2 * Math.PI) Then
A = 50000 / (Environment.TickCount - T)
T = Environment.TickCount
D = 0
End If
R = CInt(Math.Cos(D) * 60) + 180
Me.Invoke(Sub()
test()
If A <> -1 Then
Me.Text = A.ToString("##0.0##") & " CPS"
End If
End Sub)
A = -1
Loop While Not slp.WaitOne(20) '<<<<<<< the timer interval
Me.Invoke(Sub()
Me.Close()
End Sub)
End Sub
End Class
PS - I changed the code so that it does not deal with bitmaps or graphics at all - - - but still no improvement.
Maybe it is Framework Version issue ??
Thanks all
Top Tip: Toothache? Cut paper towel to 2"square. Smear with olive oil. Sprinkle on Cayenne Pepper. Fold over few times to form small wad. Tuck in between wall of mouth and gum. Leave 1 - 2 hrs. You will thank me!

Similar Messages

  • Why does google (and only google) no longer work in toolbar search box?

    The search box on the Firefox toolbar - not the google toolbar- no longer works if google is selected as search engine, gives a not found error to any search. Other search engines work, but google is broken. Google works fine anywhere else, just not from stock toolbar search box. Windows XP, Firefox 16.0.1.

    Thanks for the help, but that didn't work. "keyword.URL" was not bold and it wouldn't allow me to select reset. what next?

  • LR5.4: Why does automatic lens correction profile no longer work for SONY NEX-5N?

    Starting in LR5.4, if I attempt to apply automatic lens profile corrections, LR applies a profile for a Hasselblad LF 18-55 camera lens instead.
    Formerly, in LR 5.3, the 'make' in the lens profile pane automatially matched the EXIF 'make' of the NEX-5N; namely, "Sony", and the correct lens profile was applied automatically.
    In LR5.4, I must now manually select make = "Sony E" to appy a "setup=custom" profile before LR applies the correct lens profile.  The minute I set 'make=Sony E', LR applies a profile that matches the lens in use: either the "Sony E 18-55mm F3.5-F5.6 OSS", the "Sony E 16mm F2.8 OSS" lens or the "Sony E 55-210mm F4.5-6.3 OSS" lens that I use.
    Another issue: I am not certain of this, but I swear the LR5.4 lens profile correction now *increases* pin-cushion image distortion, whereas it worked beautifully in LR5.3.  (I should take a photograph of a grid to see if my impression is correct.)  Are the lens profile corrections applied to a camera with EXIF make="Sony E" different from those applied to an EXIF make="Sony" (i.e., the NEX-5N)?  If so, this is a shame, for it means LR no longer fully supports the NEX-5N.
    Does anyone know how to resolve this problem?
    (I believe LR5.4 may have picked up on recent product line changes announced by SONY, wherein NEX will be marketed as Sony Alpha E cameras, and I imagine they will be changing the EXIF 'make' of new cameras to reflect this.  However, that won't be changing the EXIF make of my NEX-5N.)

    Why is that so and how can I get the proper lens profile automatically if the lens does have its own Adobe profile loaded?
    Frustrated ...
    Pick the correct lens manually then choose 'Save New Lens Profile Defaults' from Setup drop down menu. Lr should remember the lens and use it as the default in future. See screenshot below

  • Why does my external hard drive no longer work

    I have a toshiba 1tb external hard drive on which I back up my Toshiba lap top. This morning when I tried to do this both USB ports on the laptop died. Thats a very short explanation for what has taken some time to establish. To get them working again I have to reboot the laptop & then I can use my wireless mouse & keyboard etc. Attach the harddrive again everything dies.
    Now the point that got me to this board is that I gave my hard drive to a colleague to copy some files (which he did) but he runs a mac! Has his mac killed my hard drive & done something that somehow means when it plugs into my laptop it kills the USB drives on that too?

    Bob you might just be right. He might have killed the cable though. I've managed to find a similar connection & I now seem to have access. Is that a natural breeding rainbow or one of those bloated stockies?

  • Why does Screen Sharing between Macs no longer work?

    Just recently many of my Mac computers have stopped Screen Sharing with each other. I cannot think of any reason why this would begin happening. These computers are 'system critical' computers so I haven't updated to Mavericks yet. One is an iMac running OS X 10.8 and the other is a Mac Mini running 10.7. Any clues?

    This could be something as simple as a bad Router Port. Try switching the Ethernet cable on one of the effected Macs to a port that you know is working. When I was running computer labs, bad ports were a commmon issue.  If that doen't work we will move on to other possible solutions.

  • Why does my hotmail account account no longer work right? Cannot forward or reply to messages without the original message being lost. Hotmail says it is a problem with the latest Firefox update.

    When I try to forward or reply to my emails in my Hotmail account, the original message disappears. Hotmail says it is a compatibility problem with the newest version of Firefox. They suggested I use Internet Explorer. Would prefer to use my old version of Firefox. How do I get it back? Or how can I get my hotmail account to work properly with the 3.6.3 version?
    == URL of affected sites ==
    http://hotmail.com

    When I try to forward or reply to my emails in my Hotmail account, the original message disappears. Hotmail says it is a compatibility problem with the newest version of Firefox. They suggested I use Internet Explorer. Would prefer to use my old version of Firefox. How do I get it back? Or how can I get my hotmail account to work properly with the 3.6.3 version?
    == URL of affected sites ==
    http://hotmail.com

  • Why does my iPad Air takes a long time to charge?

    Why does my iPad Air takes a long time to charge?

    You need to provide more detail. What do you mean by "a long time?" Are you charging it plugged into a wall socket?
    Barry

  • Why does downloading OSX Lion take so long??

    i formatted the Hard Drive from Disk Utility in order to Re-install OSX Lion...The download time first shown was like 53 hours and then after like 10 minutes it went down to 10 hours...i am pretty sure thst the internet connection i have is very fast, so why does downloading OSX Lion take so long?

    prik67 wrote:
    i formatted the Hard Drive from Disk Utility in order to Re-install OSX Lion...The download time first shown was like 53 hours and then after like 10 minutes it went down to 10 hours...i am pretty sure thst the internet connection i have is very fast, so why does downloading OSX Lion take so long?
    It's about 4GB, from memory, and the download speed can be affected from things like site traffic or variations in speed from your own ISP. But in general, it IS a very large download. Also never put your trust in a computer telling you how much time is left to download. As you can see, it recalculates everything more often and more quickly than the Tax Department! (Oh, and don't watch it. You know the old saying)
    Cheers
    Pete

  • Why does my iphone 4 take soooo long to stream video?

    Why does my iphone 4 take soooo long to stream a video???  I will have an iphone 3GS next to it, and we will play a youtube video at the same time, and the 3GS goes significantly faster.  Any advice??

    Bad cable? Bad USB port? Something corrupt in the album itself?
    We need more info as to what your configuration is and what you've tried.

  • Why does downloading from iCloud take so long now?

    I've been using Match since it was released. I'm used to the download times required for hour-length albums, playlists, and hi-def TV programs.
    My memory is that a year ago, downloading an hour-long music album that was bought on iTunes in iTunes Plus format (256Kbs) took abouit 5-10 mins. So why does it now take ONE HOUR?!?
    Likewise, my memory is that a year ago, downloading an hour-long hi-def TV episode that was bought on iTunes took abouit 20-30 mins. So why does it now take TWO HOURS?!?
    My infrastructure is the same: broadband connection with over 100Mbps down, iPhone 4s, iPad 3.
    WHY has downloading from Match gotten SO SLOW on iOS devices? On my new iMac it is blazing fast. And a year ago, it was rather quick (as detailed above).
    Anyway who has info on this, would greatly appreciate seeing it posted. Thanks.

    prik67 wrote:
    i formatted the Hard Drive from Disk Utility in order to Re-install OSX Lion...The download time first shown was like 53 hours and then after like 10 minutes it went down to 10 hours...i am pretty sure thst the internet connection i have is very fast, so why does downloading OSX Lion take so long?
    It's about 4GB, from memory, and the download speed can be affected from things like site traffic or variations in speed from your own ISP. But in general, it IS a very large download. Also never put your trust in a computer telling you how much time is left to download. As you can see, it recalculates everything more often and more quickly than the Tax Department! (Oh, and don't watch it. You know the old saying)
    Cheers
    Pete

  • HT3728 Why does time capsule every day or so stop backing up? Wifi still seems to work. Time capsule is only a few weeks old and is connected via Ethernet to the router and iMac.

    Why does time capsule go missing from the network. The green light is lit at all times. I am unable to use the software the only thing I can do is power cycle time capsule, by unplugging and plugging the mains back in.
    My time capsule is only a few weeks old, any ideas?
    I am new to apple products very impressed with iPhone 5, I pad, iMac. Really not sure about time capsule!
    Thanks

    An external drive is much more reliable.. the issue has to do with network connection and loss of something.. although I am sorry I cannot tell you exactly what. The computer is still connected, still works on internet but has actually lost the hard disk.. lost and cannot find it without a restart.
    If you want to try a few changes it can help.
    1. If you are connected by ethernet make sure wireless is off in the imac.. having only one network connection is better than two.
    2. Redo the TC setup with all short names.. no spaces.. pure alphanumeric. Apple has these long names with spaces and characters like apostrophe by default but they are not a help.
    3. If the TC is the main router then reduce the dhcp lease time.. make it 20min.. that keeps everything refreshed and up to date.
    None of those fix it but they may help stretch out the interval.

  • Why does my iPad say printer no longer available?

    Why does my iPad say printer no longer available?

    The printer is either off or no longer on the same network as iPad.
    Try rebooting router and printer.

  • Why does Time Machine disappear?

    Why does Time Machine disappear each restart?

    Suggest that you power cycle the entire network, as things are likely out of sequence
    Power every device off on the network, order is not important
    Wait a few moments, then start the modem first and let it run by itself for 2-3 minutes
    Start the Time Capsule the same way
    Start each network device one at a time about a minute apart
    Check for proper operation

  • Why does error code 4005 pop up when i try to restore my ipod 5?

    why does error code 4005 pop up when i try to restore my ipod 5?

    Have you tried this support article ?      http://support.apple.com/kb/ts3074

  • My Time Capsule expired and no longer works. My printer (a HP) will now not work as it still wishes to connect through the Time Capsule. It will not allow itself be recognised through a USB connection to my Mac. Anyone got any ideas?

    My Time Capsule expired and no longer works. My printer (a HP) will now not work as it still wishes to connect through the Time Capsule. It will not allow itself be recognised through a USB connection to my Mac. Anyone got any ideas?

    You will need to install the printer on your Mac
    Open System Preferences (gear icon) on the dock
    Open Print & Fax
    Click the + (plus) button at the bottom of the printer list
    Wait for your printer to appear in the next box, then click it to highlight it
    Click Add at the lower right
    Be sure to select the correct printer when you try to print as you will see your printer listed twice. Good idea to make the printer now installed on your Mac the default printer so you do not have to choose which printer to use each time you want to print.
    You can also go into Print & Fax, select the printer associated with the Time Capsule and click the - (minus) button if you want to delete that location.

Maybe you are looking for

  • I just installed a minor Firefox update and all my previous tabs are gone. How do I get them back?

    I installed a Yahoo suggested Firefox update. I had approximately 10 tabs open prior to the update now they have disappeared. I need to get them back. Thank you

  • Automation 'getting stuck'

    Hi - I don't think I've had this happen before but some of my automation keeps getting 'stuck'. For example I have a Low Pass Filter on a drum part which is automated to sweep from 20000Hz right down to 20Hz over a 4 bar period (and then back up agai

  • Adding Attachments in a table through personalization

    Hi, I am a newbie to OAF and have a requirement where we need to add a attachments in table in an Standard Page through personalization. This page is actually a create page for prospective suppliers (iSupplier Module) The table doesnt have an EO and

  • Unable to access storage 2530

    Hi Friends, After did a factory reset of my 2530 storage i am unable to access now even controller IP's are not pinging. I tried via serial but terminal does not accepting the break signal . Controller boot messg; ú -=<###>=- Attaching interface lo0.

  • JWS offline + JPA/Eclipselink fails

    Hi, We're using JPA in our web start enabled application. We have the latest version of the Eclipselink jar (1.1.2). When starting the application in online mode, everything runs fine, but we can see that the jar file containing META-INF/persistence.