0

I want to have my UI update every 30ms so I have some images animate while things are being processed with some async tasks.

No matter what I do or which timer I use (System.Threading.Timer or System.Windows.Forms.Timer) when things get busy the most frequent my timer is updated is about 1 second. I understand Windows is not a real-time operating system, so I won't be able to get it perfectly on 30 ms, but there's got to be some way of making this timer function have more priority and trigger more frequently!

static DateTime s_mLastTick = DateTime.Now;

mAnimationTimer = new System.Threading.Timer((state) =>
{
    DateTime now = DateTime.Now;
    Debug.WriteLine("MS since that run: " + now.Subtract(s_mLastTick).TotalMilliseconds);
                s_mLastTick = now;

    this.InvokeIfRequired(() =>
    {
        AnimateImages();
    });
}, null, 0, 30); // doesn't matter what I set this 30 to, the best log output I can get is ~1000 ms during intense computation

There's got to be a way of doing this.. any ideas?

Thanks!

user3147973
  • 426
  • 2
  • 4
  • 18
  • It seems that you have reached the limits of your machine capabilities. You should try optimizing the `AnimateImages` method for performance. – Theodor Zoulias Feb 18 '20 at 09:15
  • Apologies, I wasn't clear. The freezing and hiccups I experience is because of async / await calls that happen while the images are animating, not the AnimateImages() themselves. – user3147973 Feb 19 '20 at 17:50
  • Then you should include the code that contains these `await`s. Otherwise what can we say for code that we can't see? – Theodor Zoulias Feb 19 '20 at 20:45
  • @Theodor-zoulias Nothing. That code is irrelevant to my question. – user3147973 Feb 20 '20 at 21:27
  • I can't put a checkmark on this since it is a duplicate, however @Mike Zboray multimedia timer class from his answer here https://stackoverflow.com/questions/24839105/high-resolution-timer-in-c-sharp did exactly what I needed. – user3147973 Feb 20 '20 at 21:29

0 Answers0