Solved

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

Posted on 1998-08-31
2
167 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 42
How do you programatically show and hide the Windows 10 On-Screen-Keyboard? 3 666
sameEnds challenge 3 159
fix34  challenge 9 118
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

770 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