M
Mythran
Sample Code (top of head):
Private mThread As Thread
Private mCounter As Long
Sub StartThread()
mThread = New Thread(AddressOf StartLoop)
mThread.Start()
End Sub
Sub StopThread()
mThread.Abort()
mThread = Nothing
MsgBox(mCounter)
End Sub
Sub StartLoop()
mCounter = 0
While True
mCounter += 1
End While
End Sub
Sub btnStartStop_Click(sender As Object, e As EventArgs) Handles
btnStart.Click, btnStop.Click
If mThread Is Nothing
StartThread()
Else
StopThread()
End If
End Sub
Now...questions:
1.) Doesn't look thread safe to me. Is It? Referring to the accessing of
the mCounter variable.
2.) How can I make it thread safe and still use the variable in both
threads? (IE: Locking var somehow???)
3.) How can I transfer data between threads? Whether it is an intrinsic
data type or not...
4.) How can I automatically detect the thread is being aborted? Basically
like an event...
Just some curiosity about threading that I have while running some thread
tests this morn
Mythran
Private mThread As Thread
Private mCounter As Long
Sub StartThread()
mThread = New Thread(AddressOf StartLoop)
mThread.Start()
End Sub
Sub StopThread()
mThread.Abort()
mThread = Nothing
MsgBox(mCounter)
End Sub
Sub StartLoop()
mCounter = 0
While True
mCounter += 1
End While
End Sub
Sub btnStartStop_Click(sender As Object, e As EventArgs) Handles
btnStart.Click, btnStop.Click
If mThread Is Nothing
StartThread()
Else
StopThread()
End If
End Sub
Now...questions:
1.) Doesn't look thread safe to me. Is It? Referring to the accessing of
the mCounter variable.
2.) How can I make it thread safe and still use the variable in both
threads? (IE: Locking var somehow???)
3.) How can I transfer data between threads? Whether it is an intrinsic
data type or not...
4.) How can I automatically detect the thread is being aborted? Basically
like an event...
Just some curiosity about threading that I have while running some thread
tests this morn
Mythran