Questo articolo è stato tradotto automaticamente. Per visualizzare l'articolo in inglese, selezionare la casella di controllo Inglese. È possibile anche visualizzare il testo inglese in una finestra popup posizionando il puntatore del mouse sopra il testo.
Traduzione
Inglese

Metodo Process.WaitForExit ()

 

Data di pubblicazione: ottobre 2016

Indica al componente Process di attendere in modo indefinito la terminazione del processo associato.

Spazio dei nomi:   System.Diagnostics
Assembly:  System (in System.dll)

public void WaitForExit()

Exception Condition
Win32Exception

Non è stato possibile accedere all'impostazione di attesa.

SystemException

Non è stato impostato alcun Id di processo e non è presente alcun Handle da cui è possibile determinare la proprietà Id.

-oppure-

A questo oggetto Process non è associato alcun processo.

-oppure-

Si sta provando a chiamare WaitForExit() per un processo in esecuzione in un computer remoto. Questo metodo è disponibile solo per i processi in esecuzione nel computer locale.

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
Disponibile da 1.1
Torna all'inizio
Mostra: