how to end a thread without an exception?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • buu

    how to end a thread without an exception?

    I have a thread that ends with system.threadin g.thread.curren tThread.Abort()
    method..
    ..
    but, it throws me an exception..
    is there any other way to end a thread?


  • Jeroen Mostert

    #2
    Re: how to end a thread without an exception?

    buu wrote:
    I have a thread that ends with system.threadin g.thread.curren tThread.Abort()
    method..
    .
    Don't do that. Ever.
    but, it throws me an exception..
    is there any other way to end a thread?
    >
    Sure! Just return from your thread routine and the thread will be over.

    To end a thread from another thread, set a boolean, then have the thread
    that needs to end check for that boolean and return from its thread routine.

    The only safe (and dare I say useful) way to end a thread is by explicitly
    synchronizing. There is no safe way to simply "end" a thread without knowing
    what it's doing, so it's better to let the thread end itself by signaling it.

    --
    J.

    Comment

    • Rory Becker

      #3
      Re: how to end a thread without an exception?

      Hello buu,
      I have a thread that ends with
      system.threadin g.thread.curren tThread.Abort()
      method..
      .
      but, it throws me an exception..
      is there any other way to end a thread?
      Well when you start a thread you give it a procedure to run.
      So you could trip some internal flag (viewable by the proc) which will allow
      the procedure to come to a natural end.

      --
      Rory


      Comment

      • a a

        #4
        Re: how to end a thread without an exception?





        *** Sent via Developersdex http://www.developersdex.com ***

        Comment

        Working...