(quotes >> << are from the WinAPI help)

1/. >>
The Win32 API does not provide a way to get the thread handle from the
thread identifier. If the handles were made available this way, the owning
process could fail because another process unexpectedly performed an
operation on one of its threads, such as suspending it, resuming it,
adjusting its priority, or terminating it. Instead, you must request the
handle from the thread creator or the thread itself. 
<<

2/.  Whoever creates the thread specifies its access rights.  If you didn't
create it, and it didn't have THREAD_TERMINATE, bad luck.

3/. Most importantly, >>
TerminateThread is a dangerous function that should only be used in the most
extreme cases. You should call TerminateThread only if you know exactly what
the target thread is doing, and you control all of the code that the target
thread could possibly be running at the time of the termination. For
example, TerminateThread can result in the following problems:
·       If the target thread owns a critical section, the critical section
will not be released. 
·       If the target thread is executing certain kernel32 calls when it is
terminated, the kernel32 state for the thread's process could be
inconsistent. 
·       If the target thread is manipulating the global state of a shared
DLL, the state of the DLL could be destroyed, affecting other users of the
DLL.
<<

So if you have control of the thread, I suggest you have it use ExitThread.
If you don't, post a WM_QUIT to the thread (via PostThreadMessage - you
don't need a handle for this, just the thread id).  But if you're doing your
own threading, try using Delphi's TThread instead.

Cheers,
Carl

-----Original Message-----
From: Martin Ease [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 20 February 2001 9:48 AM
To: Multiple recipients of list delphi
Subject: [DUG]: OpenThread/TerminateThread function


Hi all

To all hardened API programmers:

Has anyone used the TerminateThread function under WinNT 4.0.

It needs a handle with THREAD_TERMINATE access rights.

How do I go about retrieving such a handle.
I know under W2k I could use OpenThread, however, I can't find any
documentation for WinNT 4.0.

Any help much appreciated.
Martin


"WS SMTP relay" made the following
 annotations on 02/20/01 12:47:55
----------------------------------------------------------------------------
--

[INFO] -- Content Manager:
[MMSSOV] This e-mail message and any attachments are confidential to
Sovereign Limited and subsidiaries and subject to legal privilege. If you
have received this e-mail in error, please advise the sender immediately and
destroy the message and any attachments.  If you are not the intended
recipient you are notified that any use, distribution, amendment, copying or
any action taken or omitted to be taken in reliance of this message or
attachments is prohibited.

============================================================================
==

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"

Reply via email to