title: Timer event in C for Windows 32 console application
body: <p>I am not a Windows expert, and have only wrote a couple of GUI VB programs. I do manage K&amp;R C language and lots of assembler, and have 35+ years in embedded systems and microprocessors control applications. So I am a mostly hardware + electronics man. I know that interrupts, as used in plain, non operating systems control software or old DOS style, are no longer possible in Windows for many valid reasons. I also know that special drivers should be written and threads created if protected interrupts are to be used under Windows. So experts: I apologize if my question sounds too simple or naive. I have "searched and researched" but didn't find a <em>simple</em> solution. <a href="https://stackoverflow.com/questions/7771142/non-blocking-sleep-timer-in-c">Non-blocking sleep timer in C</a> , <a href="https://stackoverflow.com/questions/30126609/timer-to-implement-a-time-out-function/30128378#30128378">Timer to implement a time-out function</a>, <a href="https://docs.microsoft.com/en-us/windows/desktop/winmsg/using-timers" rel="nofollow noreferrer">Using Timers</a>, all use GUI or C++ or are too complicated.</p>
  
  <p>I need to write a Windows32 console application that implements a large state machine, and several communications timeout timers are needed along with some other concurrent process timers, ranging from 1 ms to several tens of minutes. Sleep() won't work because the automata keeps on working while waits for these events to signal their termination. I found this solution <a href="https://docs.microsoft.com/en-us/windows/desktop/Sync/using-a-waitable-timer-with-an-asynchronous-procedure-call" rel="nofollow noreferrer">CreateWaitableTimer with an Asynchronous Procedure Call</a>. Should this code work in K&amp;R C and how this code would be like ? If I am right, the callback function could contain the small code needed for the timers without hanging the program as Sleep() does. I am using MS Visual Studio 2012 as C compiler. I would very much appreciate any advice and help for a very simple C solution.</p>