简体   繁体   English

如何在我的C ++项目中添加计时器?

[英]How do I add a timer to my C++ project?

I have my C++ project, and I want an event to start 40 seconds after my form is loaded. 我有我的C ++项目,我希望在加载表单40秒后启动一个事件。 I know there is a timer in C++, but it only shows intervals. 我知道C ++中有一个计时器,但它只显示间隔。

I'm using Visual Studio 2008. I'm creating a Windows Form Application. 我正在使用Visual Studio 2008.我正在创建一个Windows窗体应用程序。 Do you guys know what function I have to use? 你们知道我必须使用什么功能吗?

使用40秒间隔设置计时器,并在首次触发计时器时将其移除。

Are you talking about the .NET Timer ? 你在谈论.NET 计时器吗? Why doesn't it work for you? 为什么它不适合你? That link provides examples (assuming that's what you're talking about) of setting it up and then after it's gone off you can just dispose of it so your event doesn't start multiple times. 该链接提供了设置它的示例(假设您正在讨论的内容),然后在它关闭之后您可以将其丢弃,以便您的事件不会多次启动。

EDIT : The interval is in milliseconds, so just multiply your seconds amount by 1000. ie for 40 seconds, 40 * 1000 = 40000 . 编辑 :间隔以毫秒为单位,因此只需将您的秒数乘以1000即40秒,即40 * 1000 = 40000

EDIT2 : As per your other comment, at the bottom of the link I provided is an example for C++. EDIT2 :根据您的其他评论,我提供的链接底部是C ++的示例。 The TimerEventProcessor is set as an EventHandler for the timer in Main and will be run when the the timer is "raised" (Visual Studio might already set that up for you when you add a Timer control to the form). TimerEventProcessor被设置为Main定时器的EventHandler ,并且在定时器被“提升”时运行(当您向表单添加Timer控件时,Visual Studio可能已经为您设置了)。 Since you only want the timer to run once and you don't need the other functionality it provides, I would simply choose to use a thread as I previously suggested: 由于您只希望计时器运行一次并且您不需要它提供的其他功能,我只需选择使用我之前建议的线程:

You could also simply have another thread, which calls sleep to wait for 40 seconds, and then starts your "event." 你也可以简单地让另一个线程调用sleep等待40秒,然后启动你的“事件”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何利用C ++ / CLI项目中的控件在我的WPF应用程序中使用? - How do I leverage a control from a C++/CLI project for use in my WPF application? 如何在我的 .Net Framework 项目中添加对 Windows 运行时组件 (C++/WinRT) 的引用 - How to add a reference to Windows Runtime Component (C++/WinRT) in my .Net Framework project 如何为C ++和C#创建一个测试项目 - How do I make a single test project for C++ and C# 如何在我的 JavaScript 中识别 Sys.UI._Timer? - How do I identify Sys.UI._Timer in my JavaScript? 如何在VS 2008 Sp1的托管Visual C ++项目中选择仅客户端框架? - How do I select the client only framework in a Managed Visual C++ project in VS 2008 Sp1? 如何在设置项目中嵌入横幅图像和/或添加删除程序图标? - How do I embed a banner image and or add remove programs icon in my setup project? 如何将 System.Windows.Forms 添加到我的 .NET 5.0 项目中? - How do I add System.Windows.Forms to my .NET 5.0 project? 如何使用 VS2010 安装项目将我的程序添加到用户开始菜单? - How do I add my program to the users start menu with VS2010 Setup Project? 如何在我的 C# Visual Studio 项目中添加 VC++ DLL 作为参考? - How can I add a VC++ DLL as a reference in my C# Visual Studio project? 我如何获得像HTML敏捷性这样的外部库来在我的C#项目中工作? - How Do I Get External LIbrary Like Html Agility To Work In My C# Project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM