使用定时器的 [英] Using of a timer

查看:105
本文介绍了使用定时器的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++应用程序,我想调用一个函数每隔1分钟。我有一位朋友这样code(感谢他)

I have a c++ application and I want to call a function every 1 minute. I have this code from one friend (thanks to him)

void CALLBACK f(HWND hwnd, UINT uMsg, UINT timerId, DWORD dwTime)
{
  printf("Hello");
}

int main() 
{
  MSG msg;

  SetTimer(NULL, 0, 1000*60,(TIMERPROC) &f);
  while(GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
//Here I have the rest of my appliation
  return 0;
}

但我不能while.So之后执行我的计划的其余部分,我在寻找一个解决方案来执行所有的code和函数f的每一分钟。

but I can't execute the rest of my program after the while.So, I'm searching for a solution to execute all the code and the function f every minute.

推荐答案

您使用的是Windows计时器消息。您的应用程序停止在的GetMessage 直到 WM_QUIT 发布到线程队列。

You are using windows timer messages. Your application stops at GetMessage until WM_QUIT is posted to the thread queue.

最简单的方法是使用一个线程,并调用F那里,然后睡一分钟。

The easiest way is to use a thread and call f there, then sleep for a minute.

这篇关于使用定时器的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆