UI dies during data processing

This is a discussion on UI dies during data processing within the Windows Programming forums, part of the Platform Specific Boards category; I have a small Windows app that accepts a data file from a user, then processes the data. During the ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    15

    UI dies during data processing

    I have a small Windows app that accepts a data file from a user, then processes the data. During the processing of the data (about 15-20 seconds) the user interface completely quits responding. Not just the buttons, but the window itself stop working. I can't close, move, minimize, or even activate. If the windows gets covered by another window, the whole thing turns white until the processing is done. Just wondering what the best way to fix this is.
    This is my first Windows program, by the way.

    Basically we have this:
    Code:
    // basic stuff
    
    switch(msg)
    {
        // ... other stuff
        case WM_COMMAND:
        {
            switch(LOWORD(wParam))
            {
                case GO_BUTTON:
                {
                    // variables      
                    while(fgets(line, 1024, file)){
                          // stuff
                          /**********
                                UI is completely dead here
                         *************/
                    }
                }
            }
        }
    
    
    }
    Last edited by fatinez; 04-13-2005 at 02:13 PM.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Solve by doing the processing in another thread.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    15
    Ok, it's been a while since I posted this. I looked up thread stuff but I cannot get it to work. Everything in GO_BUTTON is now in its own function. I absolutely cannot get a new thread to work though. How would I create a thread that calls function "go_button()"?

    We have:
    Code:
    // blah blah switch case as before
    CASE GO_BUTTON:
        go_button(hwnd);
        break;
    
    // blah blah
    How do I get go_button to run in a new thread?

    By the way, this is in C.
    Last edited by fatinez; 05-04-2005 at 02:14 AM.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    void go_button(void *hWnd);

    CASE GO_BUTTON:
    _beginthread(go_button, 0, hwnd);
    break;

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    15
    Holy crap that is easy. Thanks a million.

  6. #6
    Registered User
    Join Date
    Sep 2003
    Posts
    15
    Nevermind, I figured it out.

    Another question. I just noticed that the program is using a lot of cpu when it's just sitting there. A little debug printing showed that the WM_PAINT message is always being sent. I thought that would only be sent if the window needs redrawing. If I comment it out, the CPU usage drops to zero, where it should be. Am I missing something to only make it paint the window when needed?

    It does the same thing in a blank Dev-Cpp Win32 Application if I add the WM_PAINT to it. 100% CPU.

    Code:
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    0% CPU.

    Code:
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            case WM_PAINT:
                break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    100% CPU
    Last edited by fatinez; 05-04-2005 at 04:55 AM. Reason: Figured it out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic data processing
    By vigilance in forum C++ Programming
    Replies: 5
    Last Post: 05-07-2009, 12:17 PM
  2. Replies: 3
    Last Post: 04-18-2008, 11:06 AM
  3. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  4. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 08:31 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21