Windows app stops responding when another app is started

SJ1711 20 Reputation points
2024-05-29T13:50:34.4466667+00:00

I wrote a Windows application in Fortran using the Intel Fortran compiler within Visual Studio. The application accepts user input and then launches a lengthy numerical computation. During the computation, progress is monitored using a progress bar. When I run the application, it runs fine until I open another window. At that point, the app becomes "non-responsive": it no longer updates its progress bar, displays the "(Not Responding)" message adjacent to the app name, and displays the "Windows busy signal" (the blue rotating circle). Even though it appears to be non-responsive, the application is actually running in the background, and when it finishes the lengthy computation, everything is correct and the window becomes responsive again. When I run the application from within Visual Studio, it runs fine even when I start another application - it continues to update its progress bar and is responsive. Do you know why this behavior is occurring and do you have any suggestions on how I can get the application to run correctly outside of Visual Studio?

Windows for business | Windows Client for IT Pros | User experience | Other
Developer technologies | Visual Studio | Other
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 49,636 Reputation points
    2024-05-30T09:19:17.31+00:00

    @SJ1711 There is a pretty good description of what is happening when Windows determines that an application is "Not responding" at Preventing Hangs in Windows Applications.

    When your application uses SendMessage and UpdateWindow it is calling directly into the window procedure of the progress bar control and bypassing the message queue. So the long running calculation causes the application to stop pumping messages even though the progress bar may be updating.

    When another application is opened Windows will send messages to your application (e.g., WM_ACTIVATEAPP, WM_ACTIVATE, etc.). Now your application has messages that are sitting in the message queue but are not being dispatched. Windows detects this and flags the application as "Not responding" and the ghost window is displayed.

    Windows knows when a process is executing under a debugger and does not use the ghost window. It only appears that your application is working normally under the debugger but the same problems exist.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Wesley Li 11,275 Reputation points
    2024-05-29T16:49:08.6666667+00:00

    Hello

    The behavior you’re observing is likely due to how Windows handles application responsiveness. An application is considered to be not responding if it is not waiting for input, is not in startup processing, and has not called PeekMessage within the internal timeout period of 5 seconds.

    When your application is performing a lengthy computation, it may not be able to process Windows messages regularly, which can cause Windows to consider it as “not responding”. However, the computation is still running in the background, which is why the application becomes responsive again once the computation is finished.

    Here are some suggestions to improve the responsiveness of your application:

    Multithreading: Push expensive calculations to worker threads. This allows the main thread to continue processing Windows messages, which can prevent the application from appearing unresponsive.

    Regularly Poll the Event Queue: Make sure your application regularly polls the event queue, even during lengthy computations.

    Optimize Your Code: Look for ways to optimize your computation code to reduce the time it takes to complete.

    Check for Unusual Background Processes: Look through the Processes tab in Windows Task Manager to ensure no unrequired apps or unusual background processes are running.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.