FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Unregister-Event when called in an -Action script block can cause a hang · Issue #16154 · PowerShell/PowerShell · GitHub

Repository navigation

Unregister-Event when called in an -Action script block can cause a hang #16154

Closed

Description

Prerequisites

Steps to reproduce

Note: There may be good reasons not to call Unregister-Event from inside an -Action script block passed to Register-ObjectEvent; however:

  • A hang still shouldn't occur.
  • Guidance should be added to the docs.

The hang seems to occur when more events are pending at the time Unregister-Event is called:

$timer = [Timers.Timer]::new()
$timer.Interval = 200

$action = {
  Write-Verbose -vb "Timer fired."
  $Event.Sender.Stop()
  Write-Verbose -vb "Timer stopped."
  Unregister-Event theTimer
  Write-Verbose -vb "Event unregistered."
}

$null = Register-ObjectEvent -InputObject $timer -EventName elapsed `
                             –SourceIdentifier thetimer `
                             -Action $action

$timer.Start()

while ($timer.Enabled) {
  # A sleep period of at least twice the timer interval causes a hang.
  Start-Sleep -MilliSeconds 400
}

Write-Verbose -vb 'Done'

Expected behavior

The script should complete.

Actual behavior

The script hangs after emitting the Timer fired. and Timer stooped. messages, suggesting that the Unregister-Event call is the culprit.

Error details

No response

Environment data

PowerShell Core 7.2.0-preview.9

Visuals

No response

Activity

  1. microsoft-github-policy-service commented on Nov 16, 2023

    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  2. microsoft-github-policy-service commented on Nov 16, 2023

    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  3. microsoft-github-policy-service commented on Nov 16, 2023

    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  4. microsoft-github-policy-service commented on Nov 23, 2023

    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL