2014-12-04 5 views
0

Я хочу создать таймер, который подсчитывает секунды и отображает их, но параллельно я хочу делать другие действия. Может кто-нибудь объяснить мне, как я могу это сделать или если это возможно (в Visual Studio)?Как создать таймер в C?

ответ

1
This is one way to handle your desired actions. 

in main thread, 
-fork a child process. passing 
    1) a desired time interval 
    2) a callback function ptr 
    3) indication of oneShot or repeating timer 
    into the child process, 

in the child process: 
-begin loop 
    -sleep the passed-in-time-interval 
    -execute the call back function 
    -if non repeating timer 
    -then 
     -exit child process 
    -endif 
-end loop 

in main thread, in the call back function: 
-get current time 
-display the current time to user 
-return 

in main thread, when ready to exit, kill child thread 
Смежные вопросы