做循环和定时器 [英] Do Loops and Timers
问题描述
有人告诉我为什么我的程序在Do循环中从
调用计时器功能时会挂起。以下是代码:
公共类MainForm
Public intCounter As Double = 0
Public intMin As Double
Public intSec As Double
Private Sub btnStart_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs )处理btnStart.Click
如果btnStart.Text =" Start"然后
btnStart.Text ="停止>
否则
btnStart.Text ="开始"
结束如果
lblTimeMin.Text =" 0:"
lblTimeSec.Text =" 00"
''做同时intCounter< 600
调用MyTimer()
intCounter = intCounter + 1
intMin = Int(intCounter / 60)
intSec = intCounter Mod 60
lblTimeMin.Text = Convert.ToString(intMin&":")
lblTimeSec.Text = Convert.ToString(格式(intSec,00))
''循环
结束子
私人子MyTimer ()
昏暗的开始,完成为双倍
start = Microsoft.VisualBasic.DateAndTime.Timer
finish = start + 1
Do While Microsoft.VisualBasic.DateAndTime.Timer<完成
循环
结束子
Private Sub btnExit_Click(ByVal sender As System.Object ,_
ByVal e As System.EventArgs)处理btnExit.Click
Me.Close()
End Sub
结束班级
谢谢,
迈克
< blockquote>你好MikeS,
你可以调试并判断它是否挂在Timer调用中吗?
Private Sub MyTimer()
昏暗的开始,完成为Double
start = Microsoft.VisualBasic.DateAndTime .Timer
finish = start + 1
同时Microsoft.VisualBasic.DateAndTime.Timer<完成
循环
Hello Wolf,
计时器没有Do循环就可以工作,Do循环可以在没有定时器的情况下工作。他们不会一起工作。
Wolf Saenger写道:
你好MikeS,
你可以调试并判断它是否挂在Timer调用中吗?
Private Sub MyTimer()
昏暗的开始,完成为Double
start = Microsoft.VisualBasic.DateAndTime .Timer
finish = start + 1
同时Microsoft.VisualBasic.DateAndTime.Timer<完成
循环
Hello MikeS,
你好Wolf,
计时器在没有Do循环的情况下工作,Do循环将工作
没有计时器。他们不会一起工作。
Wolf Saenger写道:
> Hello MikeS,
你可以调试并判断它是否挂在Timer调用中吗?
< blockquote class =post_quotes>
>> Private Sub MyTimer()
Dim start,finish As Double
start = Microsoft.VisualBasic.DateAndTime.Timer
finish = start + 1
同时Microsoft.VisualBasic.DateAndTime.Timer<完成
循环
那么你在循环中的内容是什么?
你设置了吗?再一次?
Can someone tell me why my program hangs when I call a timer function from
within a Do Loop. Here is the code:
Public Class MainForm
Public intCounter As Double = 0
Public intMin As Double
Public intSec As Double
Private Sub btnStart_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnStart.Click
If btnStart.Text = "Start" Then
btnStart.Text = "Stop"
Else
btnStart.Text = "Start"
End If
lblTimeMin.Text = "0:"
lblTimeSec.Text = "00"
''Do While intCounter < 600
Call MyTimer()
intCounter = intCounter + 1
intMin = Int(intCounter / 60)
intSec = intCounter Mod 60
lblTimeMin.Text = Convert.ToString(intMin & ":")
lblTimeSec.Text = Convert.ToString(Format(intSec, "00"))
''Loop
End Sub
Private Sub MyTimer()
Dim start, finish As Double
start = Microsoft.VisualBasic.DateAndTime.Timer
finish = start + 1
Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
Loop
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Thanks,
Mike
Hello MikeS,
can you debug and tell if it is hanging in the Timer call ?Private Sub MyTimer()
Dim start, finish As Double
start = Microsoft.VisualBasic.DateAndTime.Timer
finish = start + 1
Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
Loop
Hello Wolf,
The timer will work without the Do Loop and the Do Loop will work without
the timer. They will NOT work together.
"Wolf Saenger" wrote:
Hello MikeS,
can you debug and tell if it is hanging in the Timer call ?Private Sub MyTimer()
Dim start, finish As Double
start = Microsoft.VisualBasic.DateAndTime.Timer
finish = start + 1
Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
Loop
Hello MikeS,
Hello Wolf,
The timer will work without the Do Loop and the Do Loop will work
without the timer. They will NOT work together.
"Wolf Saenger" wrote:
>Hello MikeS,
can you debug and tell if it is hanging in the Timer call ?
>>Private Sub MyTimer()
Dim start, finish As Double
start = Microsoft.VisualBasic.DateAndTime.Timer
finish = start + 1
Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
Loop
So than you what you inside the loop?
do you set the time again?
这篇关于做循环和定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!