Solved

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

Posted on 2001-08-10
4
988 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
:-)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

10 Experts available now in Live!

Get 1:1 Help Now