Re: How to use WaitforSingleObject on events

Tech-Archive recommends: Fix windows errors by optimizing your registry



"blisspikle" <erick@xxxxxxxxxxxxxx> schrieb
Thank you, that seems to be close to working. I show my final code
here, but I am wondering why the msgbox "Done" shows up before the
msgbox "In Processor_Done" shows up. It seems like it should be the
other way around?

Imports System.Threading
Imports System.Runtime.InteropServices
Public Class Form1

Dim WaitforDone As New ManualResetEvent(False)
Dim WithEvents Processor As New PLCEthernet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click


Processor.Control_Update()
WaitforDone.WaitOne(5000, True)
Msgbox("Done")


End Sub


Public Sub Processor_Done() Handles Processor.Done
Msgbox("In Processor_Done")
WaitforDone.Set()
End Sub
End Class


- The timeout expired?
- It happens starting with the second event? I haven't mentioned yet: You
must call WaitforDone.Reset before calling "Processor.Control_Update()".
Otherwise, the event is in the signaled stated still from the event before.
The next time, WaitOne will immediatelly return even though the event
hasn't occured a second time. That's why it is called a *Manual*ResetEvent.
You can also use the AutoResetEvent.

I assume that the event can not occur prior to calling Processor.Control_Update.


Armin

.


Quantcast