Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Interrupt a long time operation

Interrupt a long time operation

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiondatabase
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CodeBrain
    wrote on last edited by
    #1

    I have a long time operation. In order to be able to interrupt it, the operation runs in different shorter steps. After each step I get a callback message where I can return if I want to continue the operation or not. Since the user should be able to abort the operation I developed a modless dialog box with a cancel button. The dialog class has 2 methods: one is the event handler for the cancel button (I set an internal flag if the user clicks on the button) and the other is a query method which I call in my callback handler which I mentioned above. The query method which I call regularly contains the following code MSG msg; while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) { AfxGetThread()->PumpMessage(); } // Evaluate the abort flag (set in the OnCancel method) here and return it return m_bAbortedByUser; My problem is, that I can not click on the cancel button in my dialog. But the weird thing is that I can cancel the operation by closing the dialog using the X button of the dialog. So why does the dialog gets the closing message via the X button but not the click message on the button? Anyone an idea how I can fix it? Thanks in advance.

    D D 2 Replies Last reply
    0
    • C CodeBrain

      I have a long time operation. In order to be able to interrupt it, the operation runs in different shorter steps. After each step I get a callback message where I can return if I want to continue the operation or not. Since the user should be able to abort the operation I developed a modless dialog box with a cancel button. The dialog class has 2 methods: one is the event handler for the cancel button (I set an internal flag if the user clicks on the button) and the other is a query method which I call in my callback handler which I mentioned above. The query method which I call regularly contains the following code MSG msg; while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) { AfxGetThread()->PumpMessage(); } // Evaluate the abort flag (set in the OnCancel method) here and return it return m_bAbortedByUser; My problem is, that I can not click on the cancel button in my dialog. But the weird thing is that I can cancel the operation by closing the dialog using the X button of the dialog. So why does the dialog gets the closing message via the X button but not the click message on the button? Anyone an idea how I can fix it? Thanks in advance.

      D Offline
      D Offline
      d_lite
      wrote on last edited by
      #2

      i think u should see split/merge files project by Bijesh as your lead of clue. the project use CWinThread as working process and there is a good example how to interact to that working process from your main window. you can start and you also cancel the operation too nicely there. the project you could find it codeproject, i forgat the link, but u could always search it (( _; ) ((

      C 1 Reply Last reply
      0
      • D d_lite

        i think u should see split/merge files project by Bijesh as your lead of clue. the project use CWinThread as working process and there is a good example how to interact to that working process from your main window. you can start and you also cancel the operation too nicely there. the project you could find it codeproject, i forgat the link, but u could always search it (( _; ) ((

        C Offline
        C Offline
        CodeBrain
        wrote on last edited by
        #3

        Thank you for the answer. But I think that my problem is not the interaction. And cancel the operation seems to generally work with my code (if you press the X button of the dialog). But my main problem is that although I keep the windows message loop running in my query method I don't get the OnCancel message from windows if I click on the cancel button. So I primary want to know why the messages are handled differently (has the X button message a higher priority?).

        1 Reply Last reply
        0
        • C CodeBrain

          I have a long time operation. In order to be able to interrupt it, the operation runs in different shorter steps. After each step I get a callback message where I can return if I want to continue the operation or not. Since the user should be able to abort the operation I developed a modless dialog box with a cancel button. The dialog class has 2 methods: one is the event handler for the cancel button (I set an internal flag if the user clicks on the button) and the other is a query method which I call in my callback handler which I mentioned above. The query method which I call regularly contains the following code MSG msg; while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) { AfxGetThread()->PumpMessage(); } // Evaluate the abort flag (set in the OnCancel method) here and return it return m_bAbortedByUser; My problem is, that I can not click on the cancel button in my dialog. But the weird thing is that I can cancel the operation by closing the dialog using the X button of the dialog. So why does the dialog gets the closing message via the X button but not the click message on the button? Anyone an idea how I can fix it? Thanks in advance.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Put the "long time operation" code in another thread. This will allow the primary thread to respond to user events (e.g., clicking the Cancel button). Anything else is going to be kludgy at best.

          C 1 Reply Last reply
          0
          • D David Crow

            Put the "long time operation" code in another thread. This will allow the primary thread to respond to user events (e.g., clicking the Cancel button). Anything else is going to be kludgy at best.

            C Offline
            C Offline
            CodeBrain
            wrote on last edited by
            #5

            Thanks, I will keep that in mind and look what I can do. :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups