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. Long Running Program

Long Running Program

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestiondiscussion
5 Posts 4 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.
  • B Offline
    B Offline
    BobInNJ
    wrote on last edited by
    #1

    I am currently working on a program which uses a GUI (written in C++ with MFC) to gather data from a user. When the user hits go, the program then analyzes the data and returns the results back to the user. The elapsed time between the time the user hits go and the results are returned is approximately 1 minute. In certain cases, it could be as high as 10 minutes. During that time, the program ignores any mouse clicks and when I bring up the Window’s task manager, the status of the program is that it is not responding. However, the calculations are complete, the program response as expected. However, for an end user, I do not believe that the program just hanging is acceptable. For example, if minimized and then restored it needs to be able to repaint the screen. What should I do to remedy the situation? I am thinking that if I did the calculation in a separate thread that it would solve this problem. What do you think of this idea? Maybe somebody knows a better way to handle this situation. Thanks Bob

    L R D 3 Replies Last reply
    0
    • B BobInNJ

      I am currently working on a program which uses a GUI (written in C++ with MFC) to gather data from a user. When the user hits go, the program then analyzes the data and returns the results back to the user. The elapsed time between the time the user hits go and the results are returned is approximately 1 minute. In certain cases, it could be as high as 10 minutes. During that time, the program ignores any mouse clicks and when I bring up the Window’s task manager, the status of the program is that it is not responding. However, the calculations are complete, the program response as expected. However, for an end user, I do not believe that the program just hanging is acceptable. For example, if minimized and then restored it needs to be able to repaint the screen. What should I do to remedy the situation? I am thinking that if I did the calculation in a separate thread that it would solve this problem. What do you think of this idea? Maybe somebody knows a better way to handle this situation. Thanks Bob

      L Offline
      L Offline
      Liu Xia
      wrote on last edited by
      #2

      Hi! Since the data processing procedure is running in UI thread, so no message processing operation will be performed, and that is the reason of blocking of the user interface. A simple solution is when user click the "Start" button, set the state of the UI elements (e.g. enable or disable) correctly to avoid invalid user operation and run the data operation from another thread. You can place a process bar on the form to indicat that the application is in "Busy" state while data processing is running.

      1 Reply Last reply
      0
      • B BobInNJ

        I am currently working on a program which uses a GUI (written in C++ with MFC) to gather data from a user. When the user hits go, the program then analyzes the data and returns the results back to the user. The elapsed time between the time the user hits go and the results are returned is approximately 1 minute. In certain cases, it could be as high as 10 minutes. During that time, the program ignores any mouse clicks and when I bring up the Window’s task manager, the status of the program is that it is not responding. However, the calculations are complete, the program response as expected. However, for an end user, I do not believe that the program just hanging is acceptable. For example, if minimized and then restored it needs to be able to repaint the screen. What should I do to remedy the situation? I am thinking that if I did the calculation in a separate thread that it would solve this problem. What do you think of this idea? Maybe somebody knows a better way to handle this situation. Thanks Bob

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        Yes, doing the analysis in a separate thread is the way to go. See this[^] link. /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        1 Reply Last reply
        0
        • B BobInNJ

          I am currently working on a program which uses a GUI (written in C++ with MFC) to gather data from a user. When the user hits go, the program then analyzes the data and returns the results back to the user. The elapsed time between the time the user hits go and the results are returned is approximately 1 minute. In certain cases, it could be as high as 10 minutes. During that time, the program ignores any mouse clicks and when I bring up the Window’s task manager, the status of the program is that it is not responding. However, the calculations are complete, the program response as expected. However, for an end user, I do not believe that the program just hanging is acceptable. For example, if minimized and then restored it needs to be able to repaint the screen. What should I do to remedy the situation? I am thinking that if I did the calculation in a separate thread that it would solve this problem. What do you think of this idea? Maybe somebody knows a better way to handle this situation. Thanks Bob

          D Offline
          D Offline
          dehseth
          wrote on last edited by
          #4

          try "sleep(0)" this will make windows execute its message queue here's msdn explanation: A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. A value of INFINITE indicates that the suspension should not time out.

          R 1 Reply Last reply
          0
          • D dehseth

            try "sleep(0)" this will make windows execute its message queue here's msdn explanation: A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. A value of INFINITE indicates that the suspension should not time out.

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            dehseth wrote:

            try "sleep(0)" this will make windows execute its message queue

            Actually it won't. You still need to manually flush the message queue by calling PeekMessage() in order to convey the impression of multi-threading. /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            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