| | |
Timer, tickcount, ticks?
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Hi,
You can dynamically adjust the delay amount by checking the tick count difference at each iteration thus obtaining perfect timing independent of processor load, chosen FPS or hardware bottlenecks. Put " System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.AboveNormal; " to the first line of CaptureLoop();
Loren Soth
You can dynamically adjust the delay amount by checking the tick count difference at each iteration thus obtaining perfect timing independent of processor load, chosen FPS or hardware bottlenecks. Put " System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.AboveNormal; " to the first line of CaptureLoop();
Loren Soth
•
•
Join Date: Jul 2005
Posts: 244
Reputation:
Solved Threads: 5
I see... I've set the thread priority in a slightly different location so that the entire application runs at highest. Any downsides to that?
And while I understand what you're saying, the implementation you're suggesting isn't clear. I'll work on it and post the result to see if I'm going about this in an appropriate manner.
And while I understand what you're saying, the implementation you're suggesting isn't clear. I'll work on it and post the result to see if I'm going about this in an appropriate manner.
Explainer of control logic and some basics.
"If you seek to drink from a fountain of knowledge, make sure your cup is big enough."
"If you seek to drink from a fountain of knowledge, make sure your cup is big enough."
Hi,
As long as the place you put the priority code is in the same thread as loop it won't matter. and for the delay here is a "still dynamic but not that much" kind of idea : let the loop rool for 4-5 times without delay and gather tickcount differences then average them to have see how much you code takes then Delay = (1000/FPS)-AverageCodeTimeInMSec;
Happy coding.
Loren Soth
As long as the place you put the priority code is in the same thread as loop it won't matter. and for the delay here is a "still dynamic but not that much" kind of idea : let the loop rool for 4-5 times without delay and gather tickcount differences then average them to have see how much you code takes then Delay = (1000/FPS)-AverageCodeTimeInMSec;
Happy coding.
Loren Soth
•
•
Join Date: Jul 2005
Posts: 244
Reputation:
Solved Threads: 5
Okay, this is what I've done...
And it doesn't work very well.
When I run it, even if it reports that it is using the exact same offset as the funny equations I came up with, the capture runs take longer and miss more frames than when using presets.
This is rather annoying. I still haven't been able to get my boss to get ahold of his laptop so that I can see if the hard-coded version works acceptably on that, but I don't think this self-adjusting tick offset code will perform well.
C# Syntax (Toggle Plain Text)
private void DelayAdjust() { System.Int64 frequ = 0; if (QueryPerformanceFrequency(ref frequ) != 0) { dt.AllocateFrames(8); refTick=System.Environment.TickCount; System.Int64 count1 = 0; System.Int64 count2 = 0; if (QueryPerformanceCounter(ref count1) != 0) { for(int i = 0; i<8; i++) { curTick=System.Environment.TickCount; //int t this.Times.Add(System.DateTime.Now); if (!dt.AcquireFrame(TotalFramesAcquired++)) { TotalFramesAcquired--; } decimal oops = (curTick-refTick)/((TotalFramesAcquired + missed) *frameDelay); //formerly decimal oops ticks.Add(curTick); if (oops > 1m) { missed+= Convert.ToInt32(Math.Round(oops,0)); } Application.DoEvents(); this.pbarCapture.Value=TotalFramesAcquired; } QueryPerformanceCounter(ref count2); //System.Int64 time_ms = (count2 - count1) * 1000 /(8* frequ); offset= Convert.ToInt32((count2 - count1) * 1000 /(8* frequ)); this.lPerformance.Text="Delay(in ms): " +offset.ToString();//time_ms.ToString(); } else { this.lPerformance.Text="Using preset delays"; } } else this.lPerformance.Text="Using preset delays"; dt.AllocateFrames(3); ticks.Clear(); Times.Clear(); TotalFramesAcquired = 0; missed = 0; this.pbarCapture.Value=TotalFramesAcquired; }
And it doesn't work very well.
When I run it, even if it reports that it is using the exact same offset as the funny equations I came up with, the capture runs take longer and miss more frames than when using presets.
This is rather annoying. I still haven't been able to get my boss to get ahold of his laptop so that I can see if the hard-coded version works acceptably on that, but I don't think this self-adjusting tick offset code will perform well.
Explainer of control logic and some basics.
"If you seek to drink from a fountain of knowledge, make sure your cup is big enough."
"If you seek to drink from a fountain of knowledge, make sure your cup is big enough."
![]() |
Other Threads in the C# Forum
- Previous Thread: I am new in C#... Please Guide me
- Next Thread: To Display text/subtitles on the desktop
Views: 19130 | Replies: 13
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box button buttons c# chat check checkbox class client code color combobox control conversion csharp custom database datagridview dataset datetime degrees draganddrop drawing encryption enum excel file files form format forms ftp function gcd gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





