Results 1 to 2 of 2

Thread: Terminating Threads

  1. #1
    Join Date
    Sep 2004
    Posts
    281
    Rep Power
    0

    Angry Terminating Threads

    Hi. All. I have an application that does mass data importing from xls,txt and access files into a sql server using threads. i use messaging to inform the user via progressbar at what point were are in the import as well to let them know when an error has occurred.

    The thread just will not stop. I have found that even after the thread encounters an error and i have sent and error message to the main thread to inform the user of what has happened the thread does not die and actually tries to execute the code that follows the point of error. [just so you know, I used the exit function to stop the thread when there is an error,].However this does not seem to be effective! i have also tried to let the main function terminate the thread by sending a [WM_SOS message to the main thread ] this seems to be a slow process by the time the main thread gets the message the thread has already gone terminal i.e.[ doing everything after the error point]

    any Suggestions?
    Anything or Anyone that fails to grow will eventually die. {AI}
    -------------------------------------------------
    Tomorrow is the future!
    Today Is the Tomorrow you made Yesterday!{AI}

  2. #2
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    You have to check the Terminated property throughout your thread code. So, if you encounter a problem and raise an error, the next batch of code should check 'Terminated' for its state. If it is set, do not execute. It is always good especially at the start of a loop. Start your loops like this:

    Code:
    while condition A do
    if not Terminated then....
    Now when you encounter an error and it is raised, when the loop comes back around, it sees the thread is to be terminated and stops executing. Remember a thread is almost completely unmanaged after you spawn it, so the only way to maintain some execution control if to check throughout your code whether or not to continue.

    Also you mentioned using messages to communicate between the main form and the thread, why not Synchronize those events?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •