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
Solved

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

Posted on 2001-08-10
4
1,030 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
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 2 69
How to debug For loops? 3 57
Press three keys together and trigger a function 3 61
Graphics32 under Delphi 10.1 Berlin 2 103
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 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