restart a thread

chidambaram

Well-known member
Joined
Dec 27, 2007
Messages
62
Location
Chennai,India
Programming Experience
Beginner
hi,

I am working in VB.NET 2003 (.NET framework 1.1)

In my program i am using two threads.

I start a thread for first time by thread1.start()

But after some coding line i want to stop the thread and again i want to start the thread newly..

how can i make a program ?

my code is

thread1.start()
' Some code
thread1.abort()
' Some code
thread1.resume()

but the progrma give error as

Thread is running or terminated, but it cannot be restart

thanks in advance
 
You do that the same way you did it first time; yourvariable = New Thread(addressof method)
 
Why do you need the same thread to run again? Any local variables inside the thread methods wont be the same if that's why you want to run the same one again.

Calling Abort on the thread just throws an exception inside. Not the best way to end it. What is happing inside the method that you need to stop? If its a loop use a global variable to stop the loop, then the thread will end cleanly.

Dim _running as boolean = true

Private Sub MyMethod()
while _running
'doing crap that you want to cancel.
end while
End

just set _running to false and call Join on your method.
 
Back
Top