Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

When does CreateThread return???

Posted on 2000-02-21
10
Medium Priority
?
310 Views
Last Modified: 2013-12-03
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

0
Comment
Question by:shaii
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2542762
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?
0
 

Author Comment

by:shaii
ID: 2542859
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
0
 
LVL 22

Accepted Solution

by:
nietod earned 80 total points
ID: 2542974
Where is the EndThreadFlag beign set to true/false?  If you are doing that improoperly it could lead to problems.

Anyways there is a better way to tell if a thread is running.  Use WaitForSingleObject() on the thread's handle.  This will return WAIT_OBJECT_0 if the thread has finished.  Otheriwse it will return WAIT_TIMEOUT.    (you can set the wait time to 0 to not wait at aill in this test.)
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

Author Comment

by:shaii
ID: 2543043
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
0
 

Author Comment

by:shaii
ID: 2543081
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
0
 

Author Comment

by:shaii
ID: 2543088
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
0
 
LVL 22

Expert Comment

by:nietod
ID: 2543329
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;
};
0
 
LVL 22

Expert Comment

by:nietod
ID: 2543334
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.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2543350
The constants come from winbase.h and then from winnt.h

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

Author Comment

by:shaii
ID: 2544970
10x man

I used it and it worked fine!

Shaii
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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