Solved

Using BeginThread...  How do I use EndThread?  Do i need to?

Posted on 2001-08-10
4
1,054 Views
Last Modified: 2010-04-06
We are using multiple threads in our company for the first time.  We understand them enough to be dangerous. Lol.  What I need to know is if I am calling BeginThread and it kicks off my variable procedure, without calling EndThread, am I opening myself up to memoryleaks, etc.???  I watch all the threads in the debugger and it creates the thread and then magically ends.  I believe it ends when the variable procedure ends.  If I do need to call EndThread, then where do I call it at?

Here is a snipet of code.....

// ----------------------------------------------------------------------- //
//      procedure : PingContinualEquipment
//         author : jjs
//           date : 04/01
//    description : Ping the equipment in the memtable every 10 seconds
//  modifications :
// ----------------------------------------------------------------------- //
procedure TfrmPingContinually.PingContinualEquipment(Sender: TObject; Handle: Integer;
  Interval: Cardinal; ElapsedTime: Integer);
begin
   PingThreadHandle := BeginThread(nil, 0, @PingEquipmentInList, nil, 0, PingThread);
end;

PingEquipmentInList is a variable procedure, which just pings some equipment, but does nothing to end the thread.  It also doesn?t touch any variables used by any other threads or procedures, so it is kinda isolated on its own island.  No need to resync.

Rick Whitaker
Iowa Glass Depot
0
Comment
Question by:rwhitaker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 200 total points
ID: 6374375
Windows "magically" stops the thread, when your thread function is ended. It's really a joy to use.

The only one thing you have to care about is closing the thread handle you got from BeginThread ("CloseHandle(PingThreadHandle);").

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6374377
P.S: If you have any further questions about threads, just ask. My answer just seems a bit short for 200 points, but I don't know what else to say - it's really this easy...   :-)
0
 

Author Comment

by:rwhitaker
ID: 6374491
No more questions at this time.  I was just wanting to make sure I didn't have any memory leaks that would eventually smoke our citrix/Win 2000 servers.

I am just trying to get you closer to the top of the points standings...  lol

Thanks again...

Rick
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6375199
:-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Mdi application Child forms get behind control 7 365
Delphi: Connect to running MS Outlook 4 211
SUM 2 INTEGER ARRAYS INTO 1 10 118
TlistView is Really heavy on Android 3 44
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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