Re: WaitForSingleObject() failing?
- From: "Davinder" <davinder@xxxxxxxxxxxxxxx>
- Date: Thu, 5 Jan 2006 13:03:49 +0530
Hi
Thanx everybody for the suggestions
Now i have given this statement:
DWORD ret = ::WaitForSingleObject(pApp->pWorkerThread->m_hThread,INFINITE);
As a result of this the ::WaitForSingleObject() has started to work but
another problem has come up.
The ::WaitForSingleObject() has stopped both the threads - the worker thread
& the main application thread thus hanging
my application.
where as only the main app thread(calling thread) shud have stopped & not
the worker thread.
Why is the worker thread being stopped.
Waiting for ur suggestions
Regards
"Davinder" <davinder@xxxxxxxxxxxxxxx> wrote in message
news:er7iNmREGHA.336@xxxxxxxxxxxxxxxxxxxxxxx
> Hi
> I am writing a Windows Explorer type SDI MFC Application.
> This is a multi-threaded application.
> All the threads created by me are worker threads.
>
> Now there is a situation where one worker thread is still running & the
main
> app thread creates another worker thread.
>
> I want to stop this.
> The first thread will finish then only the second thread can start.
>
> To achieve this i have used the function WaitForSingleObject() but this
> function is failing judged by its return value.
>
> The WaitForSingleObject() is used in the following fashion:
>
> void CMainFrame::OnToolsSaveInformation()
> {
> if(pApp->FileSys)
> {
> pApp->pWorkerThread = AfxBeginThread(SaveScanInfo_WorkerThread,
> (void*)pApp->MFC_Obj); // LINE 1
>
>
> DWORD ret = ::WaitForSingleObject(pApp->pWorkerThread,INFINITE); //
> LINE 5
>
> if(ret == WAIT_FAILED)
> MessageBox(_T("Wait Failed"));
> else
> MessageBox(_T("Wait Success"));
> }
>
>
> pApp->pWorkerThread = AfxBeginThread(DoRestOfTheWork_WorkerThread,
> (void*)pApp->MFC_Obj); // LINE 2
> }
>
> As evident from the above code 2 worker threads are created in Lines 1& 2.
> In Line 5 WaitForSingleThread() is being called but it is failing(Wait
> Failed msg is prompted.)
>
> I donot understand y the function is failing.
>
> Plz suggest the way out.
>
> Best Regards
>
>
>
>
>
>
.
- Follow-Ups:
- Re: WaitForSingleObject() failing?
- From: Joseph M . Newcomer
- Re: WaitForSingleObject() failing?
- References:
- WaitForSingleObject() failing?
- From: Davinder
- WaitForSingleObject() failing?
- Prev by Date: Re: How to capture ALT+ Any key in a dlg application?
- Next by Date: Re: WaitForSingleObject() failing?
- Previous by thread: Re: WaitForSingleObject() failing?
- Next by thread: Re: WaitForSingleObject() failing?
- Index(es):
Relevant Pages
|
Loading