Compartilhar via


Terminating a Process

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

The most common way for you to terminate a process is to have it return from a WinMain function call. You can also exit the primary thread of the process, using the ExitThread function.

A Windows Mobile process stops if its primary thread is closed, even if other active threads exist for the process.

ExitThread returns the exit code of the process. You can determine the exit code of a process by calling the GetExitCodeProcess function. Specify the handle to the process, which you can obtain by calling the CreateProcess or OpenProcess function. The function returns the exit code. If the process is still running, the function returns the STILL_ACTIVE status.

There are also other less common ways of terminating a process:

  • Use interprocess synchronization to instruct the process to stop.
    For more information on using interprocess communication, see Interprocess Synchronization.

  • If the process has a message queue, send a WM_CLOSE message to the main window of the process. An application might not close if it does not receive this message and might display a message box.

  • Use the TerminateProcess function, which notifies attached DLLs that the process is terminating. Use this method as a last resort.

    Note

    A process stops immediately if a related secondary thread generates an unhandled exception.

See Also

Concepts

Processes