本文介绍了重复功能每隔几秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想从程序打开,直到它关闭每隔几秒钟的瞬间重复的功能。 会是什么做这在C#?I want to repeat a function from the moment the program opens until it closes every few seconds.What would be the best way to do this in c#?推荐答案使用定时器的最佳途径。有3个基本类型,分别适用于不同的目的。Use a timer. There are 3 basic kinds, each suited for different purposes. 的 System.Windows.Forms.TimerSystem.Windows.Forms.Timer仅使用在Windows窗体应用程序。该定时器被处理的消息循环的一部分,所以该定时器可在高负载下被冻结。Use only in a Windows Form application. This timer is processed as part of the message loop, so the the timer can be frozen under high load. 的 System.Timers.TimerSystem.Timers.Timer使用,当你需要同步,使用这一个。这意味着Tick事件将启动该定时器,让你没有太多的麻烦执行GUI操作的线程上运行。Use when you need synchronicity, use this one. This means that the tick event will be run on the thread that started the timer, allowing you to perform GUI operations without much hassle. System.Threading.TimerSystem.Threading.Timer这是最高性能定时器,触发蜱在后台线程。这使您可以在后台不结冰的GUI或主线程执行操作。This is the most high-powered timer, which fires ticks on a background thread. This lets you perform operations in the background without freezing the GUI or the main thread.在大多数情况下,我建议System.Timers.Timer。For most cases, I recommend System.Timers.Timer. 这篇关于重复功能每隔几秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-07 04:49