c++ - 使用 Win32 API 在 C++ Builder 中制作多线程计时器
问题描述
我有一个在主线程中运行的应用程序。现在我需要使用 Timer 事件启动一个新线程,该线程必须每 5 分钟定期调用一个方法。在那,我需要打印主线程的状态。即使主线程死了。我需要第二个线程处于活动状态打印主线程死亡或出现异常。
我尝试了示例,但我不知道如何调用 Timer 间隔,即我不知道如何实现定期调用。
以下是我尝试的示例代码片段:
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#pragma argsused
#include <tchar.h>
#include <stdio.h>
#include <errno.h>
#include <stddef.h>
#include <process.h>
#include <time.h>
#pragma comment(lib, "Winmm.lib")
void Thread_Start(void*);
int _tmain(int argc, _TCHAR* argv[])
{
_beginthread(Thread_Start, 10000, NULL);
printf("/n RS");
// getchar();
// return 0;
}
int i = 0;
void Thread_Start(void*)
{
while (i <50)
{
printf("/n Thread Started");
i++;
break;
}
}
解决方案
推荐阅读
- c# - 在 .Net Core 中为 Excel RTD() 函数编译 IRtdServer 接口
- sharepoint - 如何使用 sharepoint pnp 将列值添加到 ClientSidePage?
- php - 从 PHP 运行 PowerShell 命令以执行带参数的 HTA
- python - 用python中的可变网址标记HTML中的单词?
- php - 解析以多种格式传递的数据......如何从中获取我需要的数据
- python - 预测模式下 tensorflow faster-rcnn 的输入图像大小?
- javascript - MongoDb 字段加密
- ios - 尝试拒绝等待审核的二进制文件时出现“您无法拒绝当前状态下的应用程序版本”错误
- swiftui - SwiftUI:如何删除 VStack 中视图之间的边距?
- python - Python 将字符串写入文件并保留 \r