I came up with nearly the same method as the first example you posted. However, I found that m_configevent.WaitOne() was only executed after the UI input was complete, which obviously left Thread B still running.
'At class level
Dim m_configevent As New AutoResetEvent(False)
Dim m_configresult As Integer
Private Delegate Function ConfigScreen_Delegate(ByVal CategoryID As Integer, ByVal CategoryDescription As String, ByVal ItemID As Integer) As Integer
Private Function ConfigScreen(ByVal CategoryID As Integer, ByVal CategoryDescription As String, ByVal ItemID As Integer) As Integer
If (Me.InvokeRequired) Then
'Non-UI thread executing
Dim args As Object() = {CategoryID, CategoryDescription, ItemID} ' Make arguments for the delegate.
Dim cdelegate As ConfigScreen_Delegate ' Make the delegate.
cdelegate = AddressOf ConfigScreen
Me.Invoke(cdelegate , args)
m_configevent.WaitOne()
'Return result
Return m_configresult
Else
'UI thread executing
'Do stuff relating to user input
m_configresult = 10 'Result of user input
'Allow waiting thread to return
m_configevent.Set()
Return 0
End If
End Function
As regards the last example you posted I got an error on the DirectCast, and didn't understand how this would be stopping Thread B
PS I really appreciate the time you have already spent on this problem....