Link to home
Start Free TrialLog in
Avatar of Zentani Mohamed Fawzi Zentani
Zentani Mohamed Fawzi Zentani

asked on

how to pause form process

how to stop form process for tracing
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Please provide more detail. We need to know your environment. Is this Visual Studio? Is this Java? Are we talking about a Web form in the browser - which browser? Remember, we're not looking over your shoulder.

However, whatever your environment; you just need to set a breakpoint on the line of code you want to debug. In Visual Studio, go to that line and press F9. It will put a maroon(ish) highlight on the line, and when you execute your application from VS, it will stop when it gets to that line of code.
a form process will run a so-called message loop.

at Windows the code for this loop might look like

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    BOOL bRet;

    while(TRUE)
    {
        bRet = GetMessage(&msg, NULL, 0, 0);

        if (bRet > 0)  // (bRet > 0 indicates a message that must be processed.)
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else if (bRet < 0)  // (bRet == -1 indicates an error.)
        {
            // Handle or log the error; possibly exit.
            // ...
        }
        else  // (bRet == 0 indicates "exit program".)
        {
            break;
        }
    }
    return msg.wParam;
}

Open in new window


you see the loop is endless because the while condition is always true.

it looks for new messages which are taken from a message queue.

any message will be removed from queue with getmessage, so each message was handled only once. to keep the system going, the handling of the messages must add new messages to the queue. if a quit message was received, the loop stops.

the handling of messages was done in the translate and especially in the dispatch function. depending on the message code and message parameters, translate and dispatch will call functions (called handlers) which are specific for the message and which were provided by the programmer of the form process.

one way to stop a form process in the debugger would be to set a breakpoint somewhere into the message loop, say at the statement where it calls DispatchMessage. if you do so, the process was stopped in the debugger immediately because the message loop normally is always busy. each mouse move or key stroke will cause messages. even on idle times an idle message was sent and could be handled by handler functions. because of that you rarely wouldn't be able to detect a specific message - say from a mouse click on a button - without skipping thousands of other Messages which are not of interest in the moment. so the better idea is to set breakpoints to handler functions which you have provided to handle messages and which were called via the DispatchMessage function.

for example if you provided a function OnClickButton1 which was called when the user clicks to a button in the current form with the left mouse button, you would set the breakpoint into this function and after you clicked the button the debugger would stop in the OnButtonClick1 where you could go on step by step or examine variables, and more.

Sara
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.