I cant start a timer

  • Thread starter Thread starter Crirus
  • Start date Start date
C

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?
 
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
 
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?
 
If I set the interval property before call for Start, first raise of the
tick event never occur...
Only when I call just start from second thead event handler


In fact, my goal is to signal to user that a connection to internet is on
the way and wether the connection was succesfull or failure...the tick event
should just make a short flash efect by changing the backfround of the
status control

But I cant use that timer as I whould espect

Crirus said:
Yes, there are anothers? That server one?
 
Hi MVP Herfried,
A 'System.Windows.Forms.Timer'?


I see you post questions for details in many issues but then never come back
for a final answer...
Is just a sign you are alive around here?
I whould like you to give an answer instead of just hope for help, even
considering many differend approches...

Should I bother to give you details in the future?

herzliche Grüße,

Crirus
 
Hi Crirus,

I tried to figure out what is your problem but could not real get it, I
thought that I did something you are saying now and I know that it did give
me a lot of headache.

Some weeks ago I have copied some code that Armin did contribute to this
group. I still did not use or look deep to it, but it is from Armin, so I
think it will work fine.

I think to remember me, that the problem was from someone who did want to
make a progressbar going from out another thread.

Here is the code, take a look yourself, because you have seen what I wrote
about my knowledge from it. (But in a first sight I think you can use it)

Cor

\\\By Armin Zingler
Private m_Thread As MyThread

Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click

m_Thread = New MyThread
AddHandler m_Thread.Progress, AddressOf OnProgress
AddHandler m_Thread.Done, AddressOf OnDone
m_Thread.Start()
End Sub

Public Delegate Sub ProgressDelegate(ByVal Progress As Integer)

Private Sub OnProgress(ByVal Progress As Integer)
If Me.InvokeRequired Then
Me.Invoke(New ProgressDelegate( _
AddressOf OnProgress _
), New Object() {Progress})
Else
Me.Button1.Text = Progress.ToString
End If
End Sub

Private Sub OnDone()
m_Thread = Nothing
End Sub
////
Class MyThread
Public Event Progress(ByVal Progress As Integer)
Public Event Done()

Private m_Thread As Thread

Public Sub Start()
m_Thread = New Thread(AddressOf ThreadStart)
m_Thread.Start()
End Sub

Private Sub ThreadStart()
Dim i As Integer
For i = 1 To 100
Thread.Sleep(100)
RaiseEvent Progress(i)
Next
RaiseEvent Done()
End Sub

End Class
///
 
Well, the timer issue is solved... I just used a wrong type of timer..
thread timer fit to my problem
Seems that Windows timer get stucked in multithreading environment....

Anyway hte rogress bar thing could help me in another future issue..

thanks
 
* "Crirus said:
Yes, there are anothers? That server one?

'System.Threading.Timer' and 'System.Timers.Timer', but both of them do
not have a 'Tick' event. So I assume you use the Windows Forms timer.
This timer is designed for use in Windows Forms and must be used on a
form. Instance members are not thread safe.
 
* "Crirus said:
I see you post questions for details in many issues but then never come back
for a final answer...

See my reply to your other answer. Sometimes I miss older posts because
my newsreader skips old threads. I feel sorry for that! I have
increased the number of recent threads now.
 
Back
Top