How to restart a thread with new parameters
-
Hi, Can anyone tell me the solution to this problem. I have built a procidure wrapped in a class that takes a parameter.This procidure is called normally by starting a thread. When an event occures, it is required to call the procidure with new paramater. A code snippet would be like this. Private Sub btnReceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReceive.Click remote = New RemoteConnection 'this is the class trListen1 = New Thread(AddressOf remote.ReceiveMessage) remote.msg = "Message has been received." trListen1.Start() End Sub Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click If trListen1.IsAlive = True Then trListen1.Abort() Else remote = New RemoteConnection trListen2 = New Thread(AddressOf remote.ReceiveMessage) remote.msg = "Message has been received,answer is here." trListen2.Start() End If End Sub But this does not work. How this can be handled? Thanks. reman
-
Hi, Can anyone tell me the solution to this problem. I have built a procidure wrapped in a class that takes a parameter.This procidure is called normally by starting a thread. When an event occures, it is required to call the procidure with new paramater. A code snippet would be like this. Private Sub btnReceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReceive.Click remote = New RemoteConnection 'this is the class trListen1 = New Thread(AddressOf remote.ReceiveMessage) remote.msg = "Message has been received." trListen1.Start() End Sub Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click If trListen1.IsAlive = True Then trListen1.Abort() Else remote = New RemoteConnection trListen2 = New Thread(AddressOf remote.ReceiveMessage) remote.msg = "Message has been received,answer is here." trListen2.Start() End If End Sub But this does not work. How this can be handled? Thanks. reman
Hi Reman, What you are trying to do is reasonably clear, however...
Amer Rehman wrote:
But this does not work.
is not. How does it not work? Is an error thrown, or what? If so, at what point in this code? etc? Johan
My advice is free, and you may get what you paid for.