Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1998-08-31
2
Medium Priority
?
182 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 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

721 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