Why is Second Thread Blocked?

  • Thread starter Thread starter Charles Law
  • Start date Start date
C

Charles Law

I have a solution with two projects.

Project1:
---------

Private m_Flagged As Boolean
Private WithEvents m_Project2 As New Project2

Private Sub WaitForFlag()
m_Flagged = False

Do While Not m_Flagged
Thread.Sleep(1)
Loop

MessageBox.Show("Event Occurred.")

End Sub

Private Sub FlagEvent(...) Handles m_Project2.EventOccurred
m_Flagged = True
End Sub

Project2:
---------

Public Event EventOccurred(...)

Private Sub WaitForEvent()

'If Some Event Occurred Then
RaiseEvent EventOccurred(...)
'End If

End Sub


WaitForEvent in Project2 is started on a new thread. The message in
WaitForFlag (Project1) is never displayed as the code stands above. If I
replace the Sleep(1) with DoEvents then it does get displayed.

I thought the whole point of executing on separate threads was that I didn't
need DoEvents anymore. Have I missed something?

TIA

Charles
 
Sorry to go on about this one, but I was hoping someone might be able to
offer some insight.

I don't want to use DoEvents if I can help it because it allows the user to
click around my app, and just causes problems. I only want my other thread
to get time while the main thread waits.

Charles
 
Back
Top