G
G
Grand Silence2014-10-04 01:44:14
C++ / C#
Grand Silence, 2014-10-04 01:44:14

What is the best way to make a periodic call to a C# procedure in a static class?

In general, the Timer_ResetIdle method should be called every minute. What is the best way to do this in terms of CPU load? There was an option with a timer, but I never got to the working version. It turned out to be done through the creation of a new thread, in which there was a cycle calling Thread.Sleep - a bad option, as for waiting, moreover, it has errors. Actually, I repeat, how does the most rational option for CPU efficiency look like on .NET?
Code Template...

<b>static </b>class PowerMgr
{
        ....
        const uint RESET_IDLE_TIMER = 0x80000001;

        private static void Timer_ResetIdle(object arg)
        {
            SetThreadExecutionState(RESET_IDLE_TIMER);
            ......
        }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gleb_kudr, 2014-10-04
@gleb_kudr

> Thread.Sleep
Oh oh, don't do that.
There is a wonderful System.Timers.Timer , which should be used. You can also use another class for timers - System.Threading.Timer, here is an article that describes their differences well: msdn.microsoft.com/en-us/magazine/cc164015.aspx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question