Click here to Skip to main content
15,914,419 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Find Window Handles of a process Pin
parths8-Jul-03 23:14
parths8-Jul-03 23:14 
QuestionI have written a pipe-like class. Would you tell me some advices on it? Pin
xiaochnegwx8-Jul-03 22:37
xiaochnegwx8-Jul-03 22:37 
GeneralSTRANGE!!!!!!!!!! Pin
vcseeker8-Jul-03 22:19
vcseeker8-Jul-03 22:19 
GeneralAnyone????????? Pin
vcseeker9-Jul-03 1:23
vcseeker9-Jul-03 1:23 
GeneralRe: Anyone????????? Pin
Rage9-Jul-03 2:04
professionalRage9-Jul-03 2:04 
QuestionWhich one is best for Wait in a thread? Pin
chen8-Jul-03 21:53
chen8-Jul-03 21:53 
AnswerRe: Which one is best for Wait in a thread? Pin
Magnus Westin8-Jul-03 23:01
Magnus Westin8-Jul-03 23:01 
AnswerRe: Which one is best for Wait in a thread? Pin
Mike Dimmick8-Jul-03 23:14
Mike Dimmick8-Jul-03 23:14 
If you just want to pause for a while, use Sleep().

Your second suggestion is for waiting for the thread object to be signalled, which it is when the thread completes execution (i.e. returns from the thread function, or calls ExitThread). In the code you've written, the call to WaitForSingleObject will return WAIT_OBJECT_0 if the thread exits before the 100ms delay is up, or WAIT_TIMEOUT if the 100ms delay expires first.

Typically you would only wait for a thread if that thread is doing something blocking that you don't want to run on the current thread. I haven't found a way, for example, of setting a timeout value for the InternetConnect function, so I launch another thread whose sole job is calling InternetConnect, then I wait on the thread handle for the desired timeout period. If the thread isn't signalled within the timeout, I assume it's going to fail and shut down the WinInet session.

Normally you'd never wait on your own thread handle, unless you're trying to use a function that requires a wait handle, but you actually want different behaviour. For example, I've needed to be able to call GetMessage with a timeout, but no such function exists. I had to call MsgWaitForMultipleObjects, but that requires at least one wait handle.

I would question whether you should be waiting: it's not really an exact science - you'll get some situations where your wait isn't long enough, due to race conditions. Is there no way to find out when the first session has been written?

--
Mike Dimmick
GeneralRe: Which one is best for Wait in a thread? Pin
chen9-Jul-03 0:09
chen9-Jul-03 0:09 
GeneralRe: Which one is best for Wait in a thread? Pin
Magnus Westin9-Jul-03 7:14
Magnus Westin9-Jul-03 7:14 
GeneralCommand Line Options Pin
BoudewijnEctor8-Jul-03 21:44
BoudewijnEctor8-Jul-03 21:44 
GeneralRe: Command Line Options Pin
giorgos8-Jul-03 21:52
giorgos8-Jul-03 21:52 
GeneralRe: Command Line Options Pin
David Crow9-Jul-03 3:55
David Crow9-Jul-03 3:55 
GeneralMDI - PLEASE URGENT Pin
giorgos8-Jul-03 21:30
giorgos8-Jul-03 21:30 
GeneralRe: MDI - PLEASE URGENT Pin
Ryan Binns8-Jul-03 21:52
Ryan Binns8-Jul-03 21:52 
GeneralRe: MDI - PLEASE URGENT Pin
giorgos8-Jul-03 22:12
giorgos8-Jul-03 22:12 
GeneralRe: MDI - PLEASE URGENT Pin
Ryan Binns8-Jul-03 22:15
Ryan Binns8-Jul-03 22:15 
GeneralRe: MDI - PLEASE URGENT Pin
giorgos8-Jul-03 22:23
giorgos8-Jul-03 22:23 
GeneralRe: MDI - PLEASE URGENT Pin
Ryan Binns8-Jul-03 22:27
Ryan Binns8-Jul-03 22:27 
GeneralABS( ) Pin
DaveE9th8-Jul-03 20:49
DaveE9th8-Jul-03 20:49 
GeneralRe: ABS( ) Pin
Ryan Binns8-Jul-03 20:54
Ryan Binns8-Jul-03 20:54 
GeneralRe: ABS( ) Pin
peterchen9-Jul-03 1:59
peterchen9-Jul-03 1:59 
GeneralRe: ABS( ) Pin
DaveE9th9-Jul-03 4:01
DaveE9th9-Jul-03 4:01 
QuestionHow to store a numeric value to *.mdb table from edit box Pin
Emre Zorlu8-Jul-03 20:14
Emre Zorlu8-Jul-03 20:14 
AnswerRe: How to store a numeric value to *.mdb table from edit box Pin
Toni788-Jul-03 20:25
Toni788-Jul-03 20:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.