Solved

Resume Terminated Thread - D7

Posted on 2006-11-08
4
633 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
4 Comments
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 100 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 100 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now