How does Windows (specifically, Vista) determine if my application is hung?

前端 未结 1 2011
盖世英雄少女心
盖世英雄少女心 2021-02-14 21:55

I have a problem very similar to the one described here: http://www.eggheadcafe.com/software/aspnet/30579866/prevent-vista-from-markin.aspx

That thread suggests that Tas

1条回答
  •  名媛妹妹
    2021-02-14 22:18

    TaskManager probably uses IsHungAppWindow to determine if an application is hung. Per MSDN, an application is considered hung if its not waiting for input, is not in startup processing, or has not not processed messages within 5 seconds. So no WM_NULL necessary.

    You don't need to consume any specific messages - just regularly pump messages and move long tasks off of the UI thread. If you can get PeekMessage to be called every 0.5 seconds, replace it with something like:

    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    

    Which will completely drain your message queue and make you appear more responsive to the user. Do not filter individual messages such as mouse messages.. You should do this more than every 0.5 seconds if possible, and longer term try to move the long work off of the UI thread.

    0 讨论(0)
提交回复
热议问题