Jack,
Thanks for the replies. You say VB6 is the same but I just tried it and
there is no second occurance, so either msgbox is different or the timer
event is different.
You are correct, VB6 appears to only allow the Paint event to continue to be
handled, it appears to block the Timer event. Without the Paint event being
handled your form will not redraw itself properly...
That piece of academia apart,
Again, you are correct, VB6 behavior is largely academia...
how do I kow what other things contain a hidden "do events"? Or do I
protect all events.
How paranoid are you? seriously?
If you are super paranoid about it, I would suggest you protect all events.
Me I only protect those routines that I know I am calling DoEvents
(explicitly) in, I rarely call DoEvents, ergo its not an issue. I do not
explicitly call MessageBox.Show from a Timer, so the fact that
MessageBox.Show allows a timer event to fire a second time is largely moot
for me. I may explicitly call MessageBox.Show within a "command" click event
(ToolBarButton Click, Button Click or MenuItem Click), seeing as
MessageBox.Show is modal, the user will not be able to click the same
ToolBar ButtonClick, Button Click or MenuItem Click event a second time, so
protecting any "command" click is moot also. Other events I would handle on
a case by case basis.
I have yet to actually come across a Windows Forms event that I
inadvertently entered a second time, hence I rarely need to protect the
event.
Note, using Synclock to protect an event wont work, as the current Thread
owns the Synclock, so when you attempt to lock the same object, you will
simply gain access to it.
Try the following, without clicking OK on the message box, you should see
multiple Timer1_Tick message boxes show up...
Private WithEvents Timer1 As System.Windows.Forms.Timer
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 4000
Private ReadOnly m_padlock As New Object
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
SyncLock m_padlock
MessageBox.Show("Timer1_Tick")
End SyncLock
End Sub
Note: I stated "I do not explicitly call MessageBox.Show from a Timer"
above, I may implicitly call MessageBox.Show, as my Global Exception
Handlers may call MessageBox.Show to display exceptions to the user, if the
Timer event happens to have an unhandled exception, then in this case I
could implicitly call MessageBox.Show. Seeing as this is an Exceptional case
(no pun intended) I'm not sure how concerned I would be with "protecting"
the Timer event from reentrancy.
Hope this helps
Jay