vb.net - Killing a thread completely in Multithreaded application -
i new vb bare me please....
can show/tell me i'm steering wrong this? running second thread in application read values registers in motion controller , updates values appropriate fields on ui every 100ms. when disconnect controller (ie...ethernet cable disconnected, lost comms), want destroy/terminate thread (thread1) completely. when reconnect ethernet cable, click button on ui reestablish comms controller, , execute runthread() sub. when want recreate thread , start it. however, when debugging part of code, appears thread (thread1) never destroyed though have verified code line (case 1) , execute it. after comms re-established, code goes right case 3 , starts thread1, expect jump case 2 , recreate thread.
public class frmmain private rmc rmclink public thread1 system.threading.thread = new system.threading.thread(addressof readregisters) private sub runthread() dim conditions integer if rmc.isconnected(pingtype.ping) = false , thread1 isnot nothing conditions = 1 elseif rmc.isconnected(pingtype.ping) = true , thread1 nothing conditions = 2 elseif rmc.isconnected(pingtype.ping) = true , thread1 isnot nothing conditions = 3 end if select case conditions case 1 thread.sleep(100) thread1.abort() case 2 dim thread1 system.threading.thread = new system.threading.thread(addressof readregisters) thread1.start() case 3 thread1.start() end select end sub
the documentation (https://msdn.microsoft.com/en-us/library/system.threading.thread.abort(v=vs.110).aspx) states terminates thread, you've found doesn't happen.
one way accomplish (i'm sure there others), create public pleasedie
property thread's subroutine(s) check periodically, , if property set true, exit subroutines within thread. before thread started, you'll of course have reset pleasedie
false.
Comments
Post a Comment