Solved

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

21 Experts available now in Live!

Get 1:1 Help Now