Re: Help with user interaction with worker thread
- From: "Vipin [MVP]" <Vipin@xxxxxxxxxx>
- Date: Mon, 30 Jan 2006 09:26:42 +0530
You should use events in this situation:-
if( myWorkerClass.DoCommand1( ) != PASS)
{
HANDLE hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
::PostMessage(m_hWnd,AM_CMD1_FAILED,0,0);
WaitForSingleObject(hEvent , INFINITE);
CloseEvent(hEvent);
}
What I would do is then package the hEvent in the parameter passed in to the
GUI thread, in your case if it is "view".
I would do view->m_hEvent = hEvent; after creating the event or package this
in the wParam or lParam
of the PostMessage.
Then in the GUI thread after the user has been prompted and shown the
MessageBox, when he click "ok"
Set the event to signaled state, so the worker thread can continue from that
point.
--
Vipin Aravind
"Danny" <fernandez.dan@xxxxxxxxx> wrote in message
news:1138574250.787275.43580@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> My question is that I have a simple worker thread that repeats the same
> two network commands, pretty straight forward. My trouble is when a
> command fails I want to ask the user if they want to repeat the command
> again. Here is a stripped down example that I want to do
>
> UINT CMyView::MyThread(LPVOID p)
> {
> (CMyView*) view = (CMyView*) p;
>
> view->Run();
>
> return 0;
> }
>
> void CMyView::Run()
> {
> while(m_executing)
> {
>
> if( myWorkerClass.DoCommand1( ) != PASS)
> {
> ::PostMessage(m_hWnd,AM_CMD1_FAILED,0,0);
> }
>
>
> if( myWorkerClass.DoCommand2() != PASS)
> {
>
> ::PostMessage(m_hWnd,AM_CMD1_FAILED,0,0);
> }
> }
> }
>
>
> LRESULT CMyView::OnCmd1Fail( WPARAM, LPARAM )
> {
> // I want to ask user,if they want to repeat command
> int rtnCode = AfxMessageBox("Command 1 failed", MB_RETRYCANCEL);
>
> if(rtnCode == IDRETRY )
> {
> // user wants to retry command
>
> }
> return 0;
> }
>
> LRESULT CMyView::OnCmd2Fail( WPARAM, LPARAM )
> {
> // I want to ask user,if they want to repeat command
> int rtnCode = AfxMessageBox("Command 2 failed", MB_RETRYCANCEL);
>
> if(rtnCode == IDRETRY )
> {
> // user wants to retry command
>
> }
> return 0;
> }
>
> So for example if myWorkerClass.DoCommand1 fails I post a command1 fail
> messge. Then I ask the user if they want to repeat this command again
> at the message handler. This is the part I'm stuck at, how do I connect
> the two with the retry and my thread.
>
> I appreciate any feedback, thanks
>
> Danny.
>
.
- Follow-Ups:
- Re: Help with user interaction with worker thread
- From: Danny
- Re: Help with user interaction with worker thread
- From: Doug Harrison [MVP]
- Re: Help with user interaction with worker thread
- References:
- Help with user interaction with worker thread
- From: Danny
- Help with user interaction with worker thread
- Prev by Date: Re: Terminating
- Next by Date: Re: Help with user interaction with worker thread
- Previous by thread: Help with user interaction with worker thread
- Next by thread: Re: Help with user interaction with worker thread
- Index(es):
Relevant Pages
|