Yep; and I've been "almost there" for a while now.
I started to worry when I put this threading code in and suddenly
started getting apparently random Exceptions all over my application
each with 15-20 lines of Stack Trace in them, /every one/ mentioning
System.Windows.-something-or-other and not a mention of /my/ code
anywhere in sight... 8-}
Here's my "thread" class :
Private Class SideStep
Friend Sub New(ByVal oCB As Rejoin, ByVal iDelay As Integer)
m_oCallbackDelegate = oCB
m_iDelay = iDelay
End Sub
Public Delegate Sub Rejoin()
Public Sub Skip()
Dim t As New Threading.Thread(AddressOf Me.Run)
t.Name = "WM_ActivateApp - SideStep"
t.Start()
End Sub
Private Sub Run()
System.Threading.Thread.Sleep(m_iDelay)
m_oCallbackDelegate.Invoke()
End Sub
Private m_oCallbackDelegate As Rejoin = Nothing
Private m_iDelay As Integer = 10
End Class
and this is how I use it
Protected Overrides Sub WndProc(ByRef m As Message)
Const WM_ACTIVATEAPP As Integer = &H1C
Select Case m.Msg
Case WM_ACTIVATEAPP
If m.WParam.ToInt32 = 1 Then
Dim d As New SideStep.Rejoin(AddressOf Me.OnAppActivate)
Dim ss As New SideStep(d)
ss.Skip()
End If
. . .
End Select
MyBase.WndProc(m)
End Sub
Regards,
Phill W.
Yes, invoking or begininvoking is the way to go - do you have any code?
seems like you are almost there...................
Phill W. said:
Can anyone recommend a good [web-based] reference on Threading (Framework
1.1)?
I'm particularly confused about how to [safely] call a method in my "main"
thread from another one. - or more, one day ;-)
I've tried creating delegates to main thread methods and Invoking themand
BeginInvoking them, but I've had some quite /horrendous/ results ...
TIA,
Phill W.