Re: Help with user interaction with worker thread



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


.



Relevant Pages

  • Help with user interaction with worker thread
    ... command fails I want to ask the user if they want to repeat the command ... if(rtnCode == IDRETRY) ... Then I ask the user if they want to repeat this command again ...
    (microsoft.public.vc.mfc)
  • Re: change system boot drive letter E to C ?
    ... Let me repeat it for you and explain.. ... For your second question about syntax of the SUBST command - know that ... windows command lines are USUALLY not case sensitive. ... my security level) - welcome to the wonderful world of the Internet and ...
    (microsoft.public.windowsxp.setup_deployment)
  • Re: How can I add the REPEAT (not Redo) command to Excels toolbar?
    ... Right click the tool bar and select Customise. ... Then click Edit on your Menu ... cells" or "Can't repeat" command and drag it to the tool bar. ... What I need is a method to add the REPEAT _command_ to the ...
    (microsoft.public.excel.misc)
  • Re: Semi-transparent box on desktop
    ... The really annoying thing about GUIs is that there's no way to describe or repeat what you just did. ... On the command line, you can do some complicated set of operations, then scroll back through your command history and cut/paste it into a script file and you'll be able to repeat that set of operations as often as you want on as many machines as you want. ...
    (Fedora)
  • Re: How can I add the REPEAT (not Redo) command to Excels toolbar
    ... Why has Microsoft neglected to add this command to the Edit category in the ... toolbar customize menu??? ... Then click Edit on your Menu ... cells" or "Can't repeat" command and drag it to the tool bar. ...
    (microsoft.public.excel.misc)