简体   繁体   English

Visual Basic-计时器不断循环

[英]Visual Basic - timer keeps looping

I'm new to the programming world. 我是编程世界的新手。

I'm trying to make a simple software which will go through 5-6 forms (showing the progress bar as a picture) and on each form display progress as a picture while some other code is being run in the background. 我正在尝试制作一个简单的软件,它将通过5-6个表单(将进度条显示为图片),并在每个表单上将进度显示为图片,同时在后台运行其他一些代码。 I've written my code and it just keeps looping the application for some reason and I don't know how to stop it from looping. 我已经编写了代码,由于某种原因它只会不断循环应用程序,我不知道如何阻止它循环。

As I said, I'm new to visual basic and programming world, so please just go easy on me, thanks! 就像我说的那样,我是视觉基础和编程世界的新手,所以请对我轻松一点,谢谢!

I just need help with stopping the timer after the HandleTimerTick() happens. 我只需要在HandleTimerTick()发生后停止计时器的帮助。 I don't know how to call the timer to stop, from the previous sub or something. 我不知道如何调用计时器从上一个子程序或其他内容中停止。 So, I just need a command to stop t.Tick once HandleTimerTick from the second sub starts. 所以,我只需要一个命令来停止t.Tick,一旦第二个子句中的HandleTimerTick启动。

If you have any simpler command to stop the code from executing for the number of seconds feel free to share. 如果您有更简单的命令来停止执行代码,请等待几秒钟。 Thanks in advance! 提前致谢!

Private Sub Delay1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim t As Timer = New Timer()
    t.Interval = 2000
    AddHandler t.Tick, AddressOf HandleTimerTick
    t.Start()


End Sub

Private Sub HandleTimerTick()
    Dim SecondForm As New Delay2
    SecondForm.Show()
    Me.Close()

End Sub

Use the proper signature for the Event handler In this way you get a reference to the Timer that trigger the event handler and you can stop it 为事件处理程序使用正确的签名通过这种方式,您可以获得触发事件处理程序的Timer的引用,并且可以停止它

Private Sub HandleTimerTick(sender As Object, e As EventArgs)

    ... your code to handle the event

    ' Stop the timer
    Dim t As System.Windows.Forms.Timer
    t = DirectCast(sender, System.Windows.Forms.Timer)
    t.Stop
End Sub

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM