Reacting to events
Events in .NET occur when something of interest happens to an object. For instance, System.IO.FileSystemWatcher
can be used to monitor a filesystem for changes; when something changes, an event will be raised.
Many different types of objects raise events when changes occur. You can use Get-Member
to explore an instance of an object for Event
members. For example, a Process
object returned by the Get-Process
command includes several events, shown as follows:
PS> Get-Process | Get-Member -MemberType Event
TypeName: System.Diagnostics.Process
Name MemberType Definition
---- ---------- ----------
Disposed Event System.EventHandler Disposed(System.Ob…
ErrorDataReceived Event System.Diagnostics.DataReceivedEventHa…
Exited Event System.EventHandler Exited(System.Obje…
OutputDataReceived Event System.Diagnostics.DataReceivedEventHa…
PowerShell can react...