Board index » cppbuilder » TThread +GetExitCodeThread()

TThread +GetExitCodeThread()


2005-01-22 03:44:14 AM
cppbuilder76
hi all,
I'm trying to use GetExitCodeThread()
with my TThread object
unsigned long ex;
GetExitCodeThread(showThread, &ex);
if(ex==STILL_ACTIVE)
{
ExitThread(ex);
}
but it never gives me STILL_ACTIVE
though I'm sure it's not exited, because I have while(1); inside a thread;
can someone have a look please?
 
 

Re:TThread +GetExitCodeThread()

"George" < XXXX@XXXXX.COM >wrote in message
Quote
I'm trying to use GetExitCodeThread()
with my TThread object
unsigned long ex;
GetExitCodeThread(showThread, &ex);
What is showThread declared as, and where is it assigned? Where exactly are
you calling GetExitCodeThread() from? Are you calling it from inside the
thread itself? If so, then you cannot do that.
Quote
but it never gives me STILL_ACTIVE
What does it actually gve you?
Quote
though I'm sure it's not exited, because I have while(1); inside a thread;
That does not guarantee that the thread is still running. There are many
factors that can terminate a thread. You did not show any of your thread
code, so I cannot tell you whether you are using GetExitCodeThread()
properly in the first place.
Gambit
 

Re:TThread +GetExitCodeThread()

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"George" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I'm trying to use GetExitCodeThread()
>with my TThread object

>unsigned long ex;
>GetExitCodeThread(showThread, &ex);

What is showThread declared as, and where is it assigned? Where exactly
are
you calling GetExitCodeThread() from? Are you calling it from inside the
thread itself? If so, then you cannot do that.

no I'm calling it from main thread!!!
not from inside the thread.
sorry for being so unclear!!!
ShowPending *showThread=NULL;
//where ShowPending is my TThread object.!!!
//and it's global variable;
Quote
>but it never gives me STILL_ACTIVE

What does it actually gve you?

>though I'm sure it's not exited, because I have while(1); inside a
thread;

That does not guarantee that the thread is still running. There are many
factors that can terminate a thread. You did not show any of your thread
//I know it's running because if I put break point it's entering the code!!!
//all the time
Quote
code, so I cannot tell you whether you are using GetExitCodeThread()
properly in the first place.


Gambit


 

{smallsort}

Re:TThread +GetExitCodeThread()

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"George" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I'm trying to use GetExitCodeThread()
>with my TThread object

>unsigned long ex;
>GetExitCodeThread(showThread, &ex);

What is showThread declared as, and where is it assigned? Where exactly
are
you calling GetExitCodeThread() from? Are you calling it from inside the
thread itself? If so, then you cannot do that.

>but it never gives me STILL_ACTIVE

What does it actually gve you?

>though I'm sure it's not exited, because I have while(1); inside a
thread;

That does not guarantee that the thread is still running. There are many
factors that can terminate a thread. You did not show any of your thread
code, so I cannot tell you whether you are using GetExitCodeThread()
properly in the first place.


Gambit


I just found a mistake myself!
it was really stupid,
I was passing GetExitCodeThread()
wrong handle.
I was passing TThread object itself.
I needed
(void *)showThread->Handle
now it returns STILL_ACTIVE
thanks for help Remy
 

Re:TThread +GetExitCodeThread()

"George" < XXXX@XXXXX.COM >wrote in message
Quote
ShowPending *showThread=NULL;
//where ShowPending is my TThread object.!!!
In that case, your call to GetExitCodeThread() is not correct.
GetExitCodeThread() expects a thread handle, but you are passing a pointer
to a class instead. Your call to GetExitCodeThread() needs to look more
like the following instead:
GetExitCodeThread((HANDLE)showThread->Handle, &ex);
Also, you are not checking the return value of GetExitCodeThread() to see
whether it fails or succeeds at all. You should always check the return
values of API functions to detect errors. For example:
if( GetExitCodeThread((HANDLE)showThread->Handle, &ex) )
// use ex as needed...
else
// failed to query the exit code, use GetLastError() to find out
why...
Gambit