如何每x秒调用一次函数 [英] How to call a function every x seconds
本文介绍了如何每x秒调用一次函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个模拟自助餐厅的程序,让客户每10到50秒进入自助餐厅。因此,我希望每10〜50秒调用一次函数,以显示要调用的函数中存在的菜单卡
I want to write a program to simulate a cafeteria in which a customer enters the cafeteria every 10 ~ 50 seconds. So I wanted a function to be called every 10~50 seconds for displaying the menu card which is present in the function to be called
推荐答案
有两种方法:1.异步2.同步
There are two approaches: 1.Asynchronous 2. Synchronous
-
假设您正在使用Win32,C ++。您可以使用Win32 API SetTimer
UINT_PTR timerid = SetTimer(NULL,0,毫秒,& callback);
UINT_PTR timerid = SetTimer(NULL, 0, milliseconds, &callback);
如果您愿意一种轮询方法最好使用类似的东西
If you would like a Polling Approach You would better use something like that
for(;;)
{
Say_Hello();
// Sleep for 50*1000ms
Sleep(50000);
}
这篇关于如何每x秒调用一次函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文