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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Lengthy operation without blocking the UI

Lengthy operation without blocking the UI

Scheduled Pinned Locked Moved C / C++ / MFC
c++comdesignquestion
3 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.
  • J Offline
    J Offline
    Jeremy Pullicino
    wrote on last edited by
    #1

    Hi, I need to call into a library to perform a lengthy operation after a user presses a button. I would like to bring up a dialog asking the user to wait a moment (no buttons on this dialog). In the background I would like the operation to be performed. When it is ready, the dialog should be destroyed. Has anyone done anything similar to this? Could someone point me to a sample or give me a few tips? I am using MFC. thanks, Jeremy Pullicino C++ Developer Homepage

    R F 2 Replies Last reply
    0
    • J Jeremy Pullicino

      Hi, I need to call into a library to perform a lengthy operation after a user presses a button. I would like to bring up a dialog asking the user to wait a moment (no buttons on this dialog). In the background I would like the operation to be performed. When it is ready, the dialog should be destroyed. Has anyone done anything similar to this? Could someone point me to a sample or give me a few tips? I am using MFC. thanks, Jeremy Pullicino C++ Developer Homepage

      R Offline
      R Offline
      RChin
      wrote on last edited by
      #2

      This sounds like a job for a background worker thread. There are two methods I use to unblock a lengthy operation: 1. pumping the message queue intermittently (in VB, this was known as DoEvents) 2. Threads. (worker or UI, depending on the usage). you should be able call your function via a worker thread, using an event to signal when the process is finished and therefore when to destroy your status dialog. Have a look at: http://users.stargate.net/~newcomer/workerthreads.htm[^], where there is an excellent article on thread usage. **I Dream of Absolute Zero


      **

      1 Reply Last reply
      0
      • J Jeremy Pullicino

        Hi, I need to call into a library to perform a lengthy operation after a user presses a button. I would like to bring up a dialog asking the user to wait a moment (no buttons on this dialog). In the background I would like the operation to be performed. When it is ready, the dialog should be destroyed. Has anyone done anything similar to this? Could someone point me to a sample or give me a few tips? I am using MFC. thanks, Jeremy Pullicino C++ Developer Homepage

        F Offline
        F Offline
        Frank Downunder
        wrote on last edited by
        #3

        Well if you want to avoid the complexity of threads in C++, just put up a modeless dialog before you start your lengthy operation. Whether it has buttons on it like a "Cancel Lenghty Operation" button is up to you - having a button like this is actually harder, because you need to be able to interrupt the operation ( you would need to set a boolean and test that boolean as often as possible inside the lengthy operation). Anyhow what you described is easier - when the operation is finished, send a meessage to your modeless window to tell it to close down!

        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