Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Método Process.WaitForExit ()

 

Publicado: octubre de 2016

Indica al componente Process que espere indefinidamente hasta que el proceso asociado termine.

Espacio de nombres:   System.Diagnostics
Ensamblado:  System (en System.dll)

public void WaitForExit()

Exception Condition
Win32Exception

No se pudo tener acceso al valor de espera.

SystemException

No se ha establecido ningún Id de proceso y no existe un Handle desde el que se pueda determinar la propiedad Id.

O bien

No hay ningún proceso asociado a este objeto Process.

O bien

Está intentando llamar a WaitForExit() para un proceso que se ejecuta en un equipo remoto. Este método está disponible únicamente para los procesos que se ejecutan en el equipo local.

WaitForExit() makes the current thread wait until the associated process terminates. It should be called after all other methods are called on the process. To avoid blocking the current thread, use the Exited event.

This method instructs the T:System.Diagnostics.Process component to wait an infinite amount of time for the process and event handlers to exit. This can cause an application to stop responding. For example, if you call M:System.Diagnostics.Process.CloseMainWindow for a process that has a user interface, the request to the operating system to terminate the associated process might not be handled if the process is written to never enter its message loop.

System_CAPS_noteNota

In the net_v35_long and earlier versions, the M:System.Diagnostics.Process.WaitForExit overload waited for F:System.Int32.MaxValue milliseconds (approximately 24 days), not indefinitely. Also, previous versions did not wait for the event handlers to exit if the full F:System.Int32.MaxValue time was reached.

This overload ensures that all processing has been completed, including the handling of asynchronous events for redirected standard output. You should use this overload after a call to the M:System.Diagnostics.Process.WaitForExit(System.Int32) overload when standard output has been redirected to asynchronous event handlers.

When an associated process exits (that is, when it is shut down by the operation system through a normal or abnormal termination), the system stores administrative information about the process and returns to the component that had called M:System.Diagnostics.Process.WaitForExit. The T:System.Diagnostics.Process component can then access the information, which includes the P:System.Diagnostics.Process.ExitTime, by using the P:System.Diagnostics.Process.Handle to the exited process.

Because the associated process has exited, the P:System.Diagnostics.Process.Handle property of the component no longer points to an existing process resource. Instead, the handle can be used only to access the operating system's information about the process resource. The system is aware of handles to exited processes that have not been released by T:System.Diagnostics.Process components, so it keeps the P:System.Diagnostics.Process.ExitTime and P:System.Diagnostics.Process.Handle information in memory until the T:System.Diagnostics.Process component specifically frees the resources. For this reason, any time you call M:System.Diagnostics.Process.Start for a T:System.Diagnostics.Process instance, call M:System.Diagnostics.Process.Close when the associated process has terminated and you no longer need any administrative information about it. M:System.Diagnostics.Process.Close frees the memory allocated to the exited process.

See the Remarks section of the P:System.Diagnostics.Process.StandardError property reference page.

LinkDemand

for full trust for the immediate caller. This member cannot be used by partially trusted code.

.NET Framework
Disponible desde 1.1
Volver al principio
Mostrar: