logo
down
shadow

Understanding waitable timers


Understanding waitable timers

By : Daniel Adarve
Date : November 22 2020, 10:31 AM
will help you The problem was not related to delphi or the code in any way. The problem was created by a Windows 7 feature that enables more than magic packets when WOL is enabled. Forcing Windows to only listen for magic packets solved the problem.
MS Link: http://support.microsoft.com/kb/941145
code :


Share : facebook icon twitter icon
Resetting Waitable Timers

Resetting Waitable Timers


By : jordancedartree
Date : March 29 2020, 07:55 AM
Any of those help Can you just call SetWaitableTimer with some very large time which isn't ever going to happen? And then call it again once you know the real time.
Update: Hack or not, the docs are pretty clear that a m-r waitable timer "remains in the signalled state until SetWaitableTimer is called". Seems to me that that's the function you're going to have to use. You'll just have to have a nice constant called 'RESET_TIMER' which is set to -2^63 or something.
Waitable timers or a timer queue? Pros and cons of each?

Waitable timers or a timer queue? Pros and cons of each?


By : user1628849
Date : March 29 2020, 07:55 AM
this one helps. A waitable timer was designed to activate code through an APC. That's pretty hard to get right due to re-entrancy issues and should only be considered if you need to run code on a thread that is otherwise occupied but blocks often enough to allow an APC to run.
Timer queues are very light-weight objects, their callback runs on a (cheap) thread from the thread pool. Almost always good for a periodic service.
Problem with waitable timers in Windows (timeSetEvent and CreateTimerQueueTimer)

Problem with waitable timers in Windows (timeSetEvent and CreateTimerQueueTimer)


By : fizz125
Date : March 29 2020, 07:55 AM
it fixes the issue Given limitations in .NET, I think you have a good approach. What is your process priority? I'm thinking it needs to be higher than normal to avoid other processes doing disk activity.
I agree with Henk that the .NET framework is not the best solution here. If garbage collection occurs, it may take a while to free objects, compact the heap, etc.
Analog to waitable timers in .NET

Analog to waitable timers in .NET


By : Yuan
Date : March 29 2020, 07:55 AM
This might help you What do you need the waitable timer for?
The default class for 'something I can wait for' in .NET is System.Threading.Tasks.Task. In .NET 4.5, you can simply use Task.Delay(milliseconds).
code :
public class WaitableTimer : WaitHandle
{
    [DllImport("kernel32.dll")]
    static extern SafeWaitHandle CreateWaitableTimer(IntPtr lpTimerAttributes, bool bManualReset, string lpTimerName);

    [DllImport("kernel32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetWaitableTimer(SafeWaitHandle hTimer, [In] ref long pDueTime, int lPeriod, IntPtr pfnCompletionRoutine, IntPtr lpArgToCompletionRoutine, [MarshalAs(UnmanagedType.Bool)] bool fResume);

    public WaitableTimer(bool manualReset = true, string timerName = null)
    {
        this.SafeWaitHandle = CreateWaitableTimer(IntPtr.Zero, manualReset, timerName);
    }

    public void Set(long dueTime)
    {
        if (!SetWaitableTimer(this.SafeWaitHandle, ref dueTime, 0, IntPtr.Zero, IntPtr.Zero, false))
        {
            throw new Win32Exception();
        }
    }
}
Does the windows scheduler skip threads that are in a waitable state? (waitable timer)

Does the windows scheduler skip threads that are in a waitable state? (waitable timer)


By : user2858979
Date : March 29 2020, 07:55 AM
it helps some times Waiting threads don't get executed. If you think about it, there is nothing to execute - the thread is waiting, so it wouldn't have anything to do with the CPU time if it was allocated.
I think your confusion might come because you think that it's the thread that does the actual check whether the object is ready. So the way you imagine it, I assume, is that WaitForSingleObject() is a function that is polling continuously, and is running in the context of your thread, and the scheduler allocates time to the thread so the thread itself can poll the object whether it is ready.
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org