how to kill a thread

J

James

below is a sample code

i read a list of machines and use ThreadPool.QueueUserWorkItem to thread
each machine using a timer. If the machine is not pingable, i wish to kill
the thread that checks the ping function, so that the next poll will not run
again.



Any advice ?



***********************************************************************

Private Sub OnTimerElapsed(ByVal sender As Object, ByVal e As
System.timers.ElapsedEventArgs)

For Each computer In Me.machines

m_utl = New utility(m_kbhotfix, m_domain, m_ntid, m_pwd)

ThreadPool.QueueUserWorkItem(AddressOf m_utl.pollmachines, computer)

Next

end sub

public class utility
Public Sub pollmachines(ByVal state As Object)

computer = CType(state, String)

If Not pingmachine(computer) Then

'how to kill the thread that does the last
pollmachines

End If

end sub

public function pingmachine as boolean
pingmachine =false
end function

end class
 
L

Lucky

as far as i know. "ThreadPool.QueueUserWorkItem" is used to as system
to run thread onbehalf of you. and it executes while your appDomain is
alive. another thing is the callback function you assigned to
"ThreadPool.QueueUserWorkItem" doesnt takes function with reference
parameter so that it is not possible to get value back into passed
parameter. other thing is that, "ThreadPool.QueueUserWorkItem" return
boolean value which tells whether your method is queued successfully or
not so here also you dont get chance to return value from your method.

in short you have to menually check for the pings and avoid such
computers instead of depending on "ThreadPool.QueueUserWorkItem" coz it
has no capability to answer whether your method successfully ckecked
for the ping or not. so u have to look for another way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top