?
Solved

Resume Terminated Thread - D7

Posted on 2006-11-08
4
Medium Priority
?
648 Views
Last Modified: 2008-03-15
Hi,

I was wondering if it is possible to resume execution or re-execute a thread after it is terminated. I have used Suspend and Resume which work but they cause the program to sometimes hang unpredictably preventing my program from closing therefore I decided not to use them. I am using the thread for reading over an indy connection.

The thread object is created during application start (FormCreate) and terminated when the connection is disconnected. The thread object is not freed on termination (my choice FreeOnTerminate := False) so I guess the reference to the thread object is still valid. I would like to have just one thread on the client and I am avoiding creating the thread on each connect. I have read that the overhead in managing multiple threads can impact performance. I have also noticed I cannot free the thread object when my application is closing down (FormClose) coz it hangs on calling Free even though the thread is terminated before freeing it.
0
Comment
Question by:martbase
3 Comments
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 400 total points
ID: 17905207
Nope. Once a thread is terminated, it's resources are gone too. All you have is the handle of the terminated process which could be used to get the final status of the thread and it's exitcode. But Windows has released all (well, most) of the resources it was using.

An application that hangs is often experiencing a deadlock, where two threads are waiting for each other to release a certain resource. Sometimes one of them will time-out but I've seen plenty of situation where the thread is waiting for an infinite amount of time for a resource to be released.
0
 
LVL 17

Assisted Solution

by:TheRealLoki
TheRealLoki earned 400 total points
ID: 17909101
if your program is hangingwhen you call suspend, then it probably means your thread is not checking "If terminated" or "suspended" often enough.
Hangs are avoidable as long as you are careful
can you paste your thread's on execute loop here?
Once we find the issue, and iron it out, you can carry on with just suspend and resume
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21133162
Forced accept.

Computer101
EE Admin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question