我不能开始计时器 [英] I cant start a timer
问题描述
嗨!
我有一个显示信息的控件...
我为它添加了一个计时器
每次应该显示一个noew mesaage我执行以下操作:
私有子ShowMsg(消息为字符串)
Me.lblStatus.Text =消息
tmrStatus.Start()
tmrStatus.Interval = 3000
tmrStatus.Enabled = True
End Sub
Private Sub tmrStatus_Tick(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理tmrStatus.Tick
如果statusColor.Equals(Color.Lime)然后
statusColor = Color.Green
否则
statusColor = Color.Lime
结束如果
Me.lblStatus.Refresh()
如果flashTime = MaxFlashes那么
flashTime = 0
tmrStatus.Stop()
否则
flashTime + = 1
结束如果
结束子
计时器处理程序永远不会被叫.. ShowMsg工作正常......这里有什么问题?
- -
Ceers,
Crirus
------------------ ------------
如果工作是好事,老板会把这一切都从你那里拿走
--- ---------------------------
Hi!
I havea control that display messages...
I added a timer to it
Every time a noew mesaage should be displayed I do the following:
Private sub ShowMsg(message as string)
Me.lblStatus.Text = message
tmrStatus.Start()
tmrStatus.Interval = 3000
tmrStatus.Enabled = True
End Sub
Private Sub tmrStatus_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrStatus.Tick
If statusColor.Equals(Color.Lime) Then
statusColor = Color.Green
Else
statusColor = Color.Lime
End If
Me.lblStatus.Refresh()
If flashTime = MaxFlashes Then
flashTime = 0
tmrStatus.Stop()
Else
flashTime += 1
End If
End Sub
The timer handler is never called.. ShowMsg work ok... what''s wrong here?
--
Ceers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------
推荐答案
非常,非常奇怪
计时器的启动方法(ShowMsg)实际上是一个从
另一个线程中提出的事件....
似乎第一次被提升,计时器运行,但第二次计时器
tick处理程序从未被调用
-
Ceers,
Crirus
------------------- -----------
如果工作是件好事,老板会把这一切都从你身上拿走
---- --------------------------
" Crirus" <铬**** @ datagroup.ro>在留言中写道
news:e2 ************* @ tk2msftngp13.phx.gbl ...
Very, Very strange
The starter method of the timer (ShowMsg) is in fact an event raised from
another thread....
Seems that first time it is raised, the timer run, but second time the timer
tick handler is never called
--
Ceers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------
"Crirus" <Cr****@datagroup.ro> wrote in message
news:e2*************@tk2msftngp13.phx.gbl...
嗨!
我有控制显示信息...
我添加了一个计时器
每次显示noew mesaage我都会做以下事情:
私人子ShowMsg(消息为字符串)
Me.lblStatus.Text =消息
tmrStatus.Start()
tmrStatus.Interval = 3000
tmrStatus.Enabled = True
End Sub
Private Sub tmrStatus_Tick(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理tmrStatus.Tick
如果statusColor.Equals(Color.Lime)那么
statusColor = Color.Green
其他
statusColor = Color.Lime
结束如果
Me.lblStatus.Refresh()
如果flashTime = MaxFlashes那么
flashTime = 0
tmrStatus.Stop()
其他
flashTime + = 1
结束如果
结束子
永远不会调用计时器处理程序.. ShowMsg工作正常......这里有什么问题?
-
Ceers,
Crirus
------------------------------
如果工作是件好事,那么老板就会把这一切都从你那里拿走
--------------------------- ---
Hi!
I havea control that display messages...
I added a timer to it
Every time a noew mesaage should be displayed I do the following:
Private sub ShowMsg(message as string)
Me.lblStatus.Text = message
tmrStatus.Start()
tmrStatus.Interval = 3000
tmrStatus.Enabled = True
End Sub
Private Sub tmrStatus_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrStatus.Tick
If statusColor.Equals(Color.Lime) Then
statusColor = Color.Green
Else
statusColor = Color.Lime
End If
Me.lblStatus.Refresh()
If flashTime = MaxFlashes Then
flashTime = 0
tmrStatus.Stop()
Else
flashTime += 1
End If
End Sub
The timer handler is never called.. ShowMsg work ok... what''s wrong here?
--
Ceers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------
第三次精简:
尝试启动计时器的第二个线程,提升事件和计时器运行
然后调用wbclient.UploadData
虽然UploadData还没有返回,但计时器勾选被触发
当wbclient.UploadData返回时,我尝试再次运行计时器并调用
threadis暂停。
这次,计时器刻度永远不会被触发...
我试着用鼠标点击来点击tick事件并且工作得很好...
只有来自secod线程的第二次调用才能工作
有意义吗?
-
Ceers,
Crirus
-------------- ----------------
如果工作是件好事,那么老板就会把这一切都从你身上带走
------------------------------
" Crirus" <铬**** @ datagroup.ro>在留言中写道
news:e2 ************* @ tk2msftngp13.phx.gbl ...
Third precisation:
The second thread that try to start timer, raise the event and the timer run
and then make a call to wbclient.UploadData
While the UploadData didnt returned yet, the timer tick is triggered
When wbclient.UploadData return, I try to run the timer again and calling
threadis paused.
This time, timer tick is never fired...
I tried to fire the tick event with a mouse click and work just fine...
Only that second call from within the secod thread dont work
Make any sense?
--
Ceers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------
"Crirus" <Cr****@datagroup.ro> wrote in message
news:e2*************@tk2msftngp13.phx.gbl...
嗨!
我有控制显示信息...
我添加了一个计时器
每次显示noew mesaage我都会做以下事情:
私人子ShowMsg(消息为字符串)
Me.lblStatus.Text =消息
tmrStatus.Start()
tmrStatus.Interval = 3000
tmrStatus.Enabled = True
End Sub
Private Sub tmrStatus_Tick(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理tmrStatus.Tick
如果statusColor.Equals(Color.Lime)那么
statusColor = Color.Green
其他
statusColor = Color.Lime
结束如果
Me.lblStatus.Refresh()
如果flashTime = MaxFlashes那么
flashTime = 0
tmrStatus.Stop()
其他
flashTime + = 1
结束如果
结束子
永远不会调用计时器处理程序.. ShowMsg工作正常......这里有什么问题?
-
Ceers,
Crirus
------------------------------
如果工作是件好事,那么老板就会把这一切都从你那里拿走
--------------------------- ---
Hi!
I havea control that display messages...
I added a timer to it
Every time a noew mesaage should be displayed I do the following:
Private sub ShowMsg(message as string)
Me.lblStatus.Text = message
tmrStatus.Start()
tmrStatus.Interval = 3000
tmrStatus.Enabled = True
End Sub
Private Sub tmrStatus_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrStatus.Tick
If statusColor.Equals(Color.Lime) Then
statusColor = Color.Green
Else
statusColor = Color.Lime
End If
Me.lblStatus.Refresh()
If flashTime = MaxFlashes Then
flashTime = 0
tmrStatus.Stop()
Else
flashTime += 1
End If
End Sub
The timer handler is never called.. ShowMsg work ok... what''s wrong here?
--
Ceers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------
*" Crirus" <铬**** @ datagroup.ro> scripsit:
* "Crirus" <Cr****@datagroup.ro> scripsit:
我有一个显示消息的控件...
我为它添加了一个计时器
I havea control that display messages...
I added a timer to it
A''系统。 Windows.Forms.Timer''?
-
Herfried K. Wagner
MVP·VB Classic,VB.NET
< http://www.mvps.org/dotnet>
A ''System.Windows.Forms.Timer''?
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
这篇关于我不能开始计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!