Seva Alekseyev
Seva Alekseyev

Reputation: 61378

Remove event handler in Powershell

In Powershell, one may hook an event on a .NET object by calling add_EventName, like this:

$MyBlock = [System.EventHandler]{Write-Host Hello}
$MyObject.add_Completed($MyBlock)

How does one remove that event handler? Or reset the event to the state with no handlers?

This arised from here.

Upvotes: 1

Views: 302

Answers (1)

Seva Alekseyev
Seva Alekseyev

Reputation: 61378

Like this:

$MyObject.remove_Completed($MyBlock)

Upvotes: 2

Related Questions