Link to home
Start Free TrialLog in
Avatar of shaii
shaii

asked on

When does CreateThread return???

Hi,
 I am using CreateThread in VB5.
I would like to know when does it return so I can execute another thread.

plz add code :)
10x
Shaii

Avatar of nietod
nietod

What do you mean?  It returns when the other thread has been created.  The other thread may or may not actually begin executing its code before CreateThread() returns.

>> plz add code :)
Code for what?
Avatar of shaii

ASKER

OK
I will make myself clear
I am recording from RS232.

I am runing a recording program in a thread
Dim lngRetVal As Long

RecThreadHwnd = CreateThread(0&, 0&, AddressOf StartRecording, lngStam, CREATE_SUSPENDED, lngThread1)

If SetThreadPriority(RecThreadHwnd, THREAD_PRIORITY_ABOVE_NORMAL) = 0 Then MsgBox "ERROR"

ResumeThread (RecThreadHwnd)

Do Until EndThreadFlag = True
     DoEvents
Loop
'now run the second recording

where EndThreadFlag is a global var that I change via a message from the program in the thread.

but this is not stable at all it works 1 out of 10 times.
I would like to know when I can run the second recording safely (... when does the thread return???)

Hope this makes it clear
Shaii
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shaii

ASKER

I couldn't find the CONST values for WAIT_OBJECT_O  and WAIT_TIMEOUT ...
didn't find them in the API viewer nor in the .h file.

well if u can plz add some code it would be perfect

10x
Shai
Avatar of shaii

ASKER

I couldn't find the CONST values for WAIT_OBJECT_O  and WAIT_TIMEOUT ...
didn't find them in the API viewer nor in the .h file.

well if u can plz add some code it would be perfect

10x
Shai
Avatar of shaii

ASKER

I couldn't find the CONST values for WAIT_OBJECT_O  and WAIT_TIMEOUT ...
didn't find them in the API viewer nor in the .h file.

well if u can plz add some code it would be perfect

10x
Shai
I heard you the first time.  :-)

>>I couldn't find the CONST values for WAIT_OBJECT_O
they are defined in windows.h somewhere.

You are using windows.h, right?

code:

bool IsThreadRunning(HTHREAD ThdHnd)
{
    return WaitForSingleObject(ThdHnd,0) != WAIT_OBJECT_0;
};
Oh, you're not using C/C++.  That's a problem.  There's no windows.h equivalent for VB is there?  I can probably tell you what those constants are.  I can't give you the code in VB.
The constants come from winbase.h and then from winnt.h

WAIT_OBJECT_0 = 0.
WAIT_TIMEOUT = 0x0102;  (that is 102 in hex).
Avatar of shaii

ASKER

10x man

I used it and it worked fine!

Shaii