DEV Community

Azrael
Azrael

Posted on

The Process.WaitForExit() method has been unavailable for the last decade.

The Process.WaitForExit() method is a commonly used method in .NET. It waits until a process has finished executing. However, in the last decade or so, this method has been reported to be unavailable and throwing the error "System.ComponentModel.Win32Exception: 'Access is denied.'" in some cases.

This is due to changes in the security model of Windows. All the way back to Windows Vista, User Account Control (UAC) was introduced, which restricted certain privileges to only administrators or applications that were run as an administrator. This included the ability to wait for a process to exit.

An attempt was made to fix this is, there was a new method called Process.Exited event. This event is raised when the process has exited. The Exited event also has most of the features as the Process.WaitForExit() method has.

Process.WaitForExit Method (System.Diagnostics) | Microsoft Learn

Sets the period of time to wait for the associated process to exit, and blocks the current thread of execution until the time has elapsed or the process has exited. To avoid blocking the current thread, use the Exited event. For code examples, see the StandardError and the ExitCode property reference pages.

learn.microsoft.com

Top comments (0)