Solved

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

Posted on 1998-08-31
2
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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