Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

thread question

Status
Not open for further replies.

ccampbell

Programmer
Aug 16, 2001
201
US
hello,
I have created a thread to launch an FTP file removal process, and I need the thread to run while my other program functions are running. Then, before my functions complete and return, I need to check the thread to make sure that it is done before I return from the functions and close the thread handle. Here is a sample of what I am doing

HANDLE m_pThread =::CreateThread( NULL,0,LPTHREAD_START_ROUTINE)LogFileThread,this,0
,&threadID);

//Need to make sure that the thread is running while the other processes are running. (Not sure what to do here)

//perform other functions here while the thread is running and doing its stuff (I have these functions already written)

//check the thread to see if it has finished its processes (this is where I am having the problem)

//If the thread has finished, return from the body of the program, if not, wait for the thread to finish.

Anyone have any ideas?
 
Code:
// do all the other stuff that needs to be done.
::WaitForSingleObject( m_pThread, INFINITE);

does that help?
-pete
 
::WaitForSingleObject( m_pThread, INFINITE);
waits for the thread to finish. If you rather want to just check at some point if it finished, call
::WaitForSingleObject( m_pThread, 0);
instead.




 
There are sevaral examples given in msdn like mtmdi,frerserve who elaborate the threading usage ..give these samples a look ...they are beautiful to get an idea..They use threading conepts fully...
Hopr it will help
cheers
:)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top