Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to terminate thread ?

17 views
Skip to first unread message

Ping Pong

unread,
Nov 26, 2004, 8:31:40 AM11/26/04
to
Dear All,

I've created thread on PostInt() and want to terminate by OnClose().

METHOD PostInt() Class cScale_Dlg
LOCAL dwThreadID AS DWORD
...
...
CreateVOThread( NULL_PTR, 0, @Running_Digit(), PTR(_CAST, SELF), 0, dwThreadID )

RETURN

STATIC FUNCTION Running_Digit()
//Show Digit from Truck Scale using Ginny Serial Class
RETURN

METHOD OnClose() CLASS cScale_Dlg
// i want to terminate only the thread here ?
// and return to do other task in application
// i've used TermiateThread() but the application was terminated.
RETURN SUPER:OnClose(oEvent)

pls help,

Ping Pong

Michael Rubinstein

unread,
Nov 26, 2004, 10:03:26 AM11/26/04
to
Dear Ping. A thread should terminate by itself upon return of the thread
function. If you have a loop in your thread function, you should provide
means to break out. In the code fragment you provided the thread function
accepts no parameters. You don't show the code either. The parameter passed
to the thread function is normally a structure. One of the structure members
can be used to communicate with the thread. Take time to look into Ginny's
code. It has a thread function that is terminated from the main thread.

Michael

"Ping Pong" <ico...@hotmail.com> wrote in message
news:95d289de.04112...@posting.google.com...

John Martens

unread,
Nov 26, 2004, 10:51:11 AM11/26/04
to
Do you need a thread or just a Timer ?

John

"Ping Pong" <ico...@hotmail.com> schreef in bericht
news:95d289de.04112...@posting.google.com...

Robert van der Hulst

unread,
Nov 26, 2004, 11:29:31 AM11/26/04
to
Hi Ping,
On 26 Nov 2004, at 05:31:40 [GMT -0800] (which was 14:31 where I live)
you wrote about: 'how to terminate thread ?'

> METHOD PostInt() Class cScale_Dlg
> LOCAL dwThreadID AS DWORD
> ...
> ...
> CreateVOThread( NULL_PTR, 0, @Running_Digit(), PTR(_CAST, SELF), 0, dwThreadID )

> RETURN

This is incorrect and dangerous:

1. You are passing a pointer to SELF. That address may and will certainly
move when the GC becomes actibe
2. You should pass dwThreadid by reference. That will return the ID of the
new thread.

CreateVOThread returns a Thread Handle. You can use this handle and call
TerminateThread() to terminate the thread.

--
Robert van der Hulst
AKA Mr. Data
Vo2Jet & Vo2Ado Support
VO Development Team
www.sas-software.nl
mrdata...@sas-software.com

Ping Pong

unread,
Nov 28, 2004, 12:09:06 AM11/28/04
to
Robert,

i've changed code as u suggested and it's work fine. Thanks for all of
replying messages.

changed code to,
1.pass dwThreadid by reference
-->CreateVOThread( NULL_PTR, 0, @Running_Digit(), PTR(_CAST, SELF), 0,
@dwThreadID )

2.CreateVOThread returns a Thread Handle. and this handle and call


TerminateThread() to terminate the thread.

-->TerminateThread( SELF:ptrSerialThread, 0 )

i've defined SELF:ptrSerialThread := CreateVOThread( NULL_PTR, 0,
@Running_Digit(), PTR(_CAST, SELF), 0, @dwThreadID ) at PostInt().

Robert van der Hulst <mrdata...@sas-software.com> wrote in message news:<1818130158.2...@sas-software.nl>...

Ginny Caughey

unread,
Nov 28, 2004, 8:36:20 AM11/28/04
to
Ping,

Although TerminateThread will kill the thread, it really isn't the Microsoft
recommended way to do so in any programming language with any version of
Windows. I agree with Michael that the best way is to have the main thread
tell the worker thread to end itself and then wait until that happens before
exiting the app.
--
Ginny

"Ping Pong" <ico...@hotmail.com> wrote in message
news:95d289de.04112...@posting.google.com...

0 new messages