本文介绍了Timer.elapsed事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我坚持使用计时器,有人可以解释一下这个事件是如何运作的吗?什么以主要形式调用,使这个模块启动?我创建了一个名为Example的模块,试图每2秒在form1标签文本hello中写入计时器,但是当我启动应用程序时没有任何反应。有帮助吗?谢谢。我正在使用WinForms 我尝试过: Imports System.Timers 公共模块示例私有aTimer作为计时器 Public Sub Main() '创建一个计时器并设置两秒间隔。 aTimer = New System.Timers.Timer() aTimer.Interval = 2000 '连接计时器的Elapsed事件。 AddHandler aTimer.Elapsed,AddressOf OnTimedEvent '让计时器触发重复事件(默认为true) aTimer.AutoReset = True '启动计时器 aTimer.Enabled = True End Sub Private Sub OnTimedEvent(source As Object,e As System.Timers.ElapsedEventArgs) Form1.Label1。 Text =hello End Sub 结束模块 解决方案 i stucked with a timer, can someone explain please how this event works? what to call in main form, to make this module start? I created a module called "Example", tried to make timer write in form1 label text "hello" every 2seconds, but when i start app nothing happens. Any help? Thanks. Im using WinFormsWhat I have tried:Imports System.TimersPublic Module example Private aTimer As Timer Public Sub Main() ' Create a timer and set a two second interval. aTimer = New System.Timers.Timer() aTimer.Interval = 2000 ' Hook up the Elapsed event for the timer. AddHandler aTimer.Elapsed, AddressOf OnTimedEvent ' Have the timer fire repeated events (true is the default) aTimer.AutoReset = True ' Start the timer aTimer.Enabled = True End Sub Private Sub OnTimedEvent(source As Object, e As System.Timers.ElapsedEventArgs) Form1.Label1.Text = " hello" End SubEnd Module 解决方案 这篇关于Timer.elapsed事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-11 23:40