Solved

Trapping a cancel button click while doing a long DAO records transfer

Posted on 1998-08-31
2
166 Views
Last Modified: 2013-11-19
I have an app that allows the user to tranfer data from one database to another.  I wish To add a cancel button.  

The user is unable to click the button during the transfer process since the primary thread is busy doing the transfer work.  I can not run my DAO transfer operation in a secondary thread since DAO only runs in primary threads(or atleast thats what Microsft says, but even when I tried it I had some memory leak issue come up).

I know this issue have been solved by many application before, which was easy if you did the work in a worker thread.  However, lie I said before DAO does not run in secondary(worker) threads and so I am not sure what to do.
0
Comment
Question by:patel4694
2 Comments
 
LVL 2

Accepted Solution

by:
prasanth earned 50 total points
ID: 1321520
Use something like the following:

void CMyClass::OnCancel()
{
   if (m_transferring)
       m_cancelled = TRUE;
   else
       CDialog::OnCancel();
}

void CMyClass::OnDoIt()
{
    m_transferring = TRUE;
    while (!m_cancelled)
    {
        StdMsgLoop();
        TransferOneDaoRecord(); // you implement this func
    }
    m_transferring = FALSE;
}

BOOL StdMsgLoop()
{
      MSG msg;
      while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
      {
            if (!AfxGetApp()->PumpMessage())
            {
                  ::PostQuitMessage(0);
                  return FALSE;
            }
      }
      return TRUE;
}
0
 

Author Comment

by:patel4694
ID: 1321521
thanks, this was very helpfull. I did not realize that messages were queued.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 48
Show shut-down message as Windows 8 shuts down. 9 85
pre4 challenge 19 94
fix34  challenge 9 105
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now