Re: WaitForSingleObject() failing?



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
>
>
>
>
>
>


.



Relevant Pages

  • Re: WaitForSingleObject() failing?
    ... >app thread creates another worker thread. ... >To achieve this i have used the function WaitForSingleObject() but this ... why are you putting this in the app when it is managed by the mainframe? ... of dumping global variables into the app is one of the worst practices I've seen. ...
    (microsoft.public.vc.mfc)
  • Re: Service crash using MSDN example code
    ... > spawned worker thread or in the handler function for the ... WaitForSingleObject(ServiceControlEvent, INFINITE) in the MyServiceStart ... You should spawn a worker thread before calling ... >> Perhaps you missed this bit of my post, as the listing i posted was ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Multhreading pb, tools for getting timings
    ... everything works fine and the worker thread is waked up by the ... > wake up by the setevent or the display is not ... "WaitForSingleObject" waiting on this event to return WAIT_OBJECT_0? ... >> first one the quit event and the second one your hMuxEvent. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: WaitForSingleObject() failing?
    ... > app thread creates another worker thread. ... > To achieve this i have used the function WaitForSingleObject() but this ... You're calling WFSO right inside a handler for the main GUI ... Figure out some other mechanism for triggering the second thread. ...
    (microsoft.public.vc.mfc)
  • WaitForSingleObject freezes application
    ... When I comment out the WaitForSingleObject line, ... the worker thread terminate correctly (it don't wait till ... m_bAbort equals TRUE, then WaitForSingleObject does ... not freeze my application.... ...
    (microsoft.public.vc.mfc)

Loading