Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell: add_xxx event handling does not work #7

Open
Jomme5 opened this issue Nov 6, 2023 · 0 comments
Open

Powershell: add_xxx event handling does not work #7

Jomme5 opened this issue Nov 6, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@Jomme5
Copy link

Jomme5 commented Nov 6, 2023

Describe the bug

using namespace System.Windows.Forms
using namespace h.hooks

Add-Type -Path .\H.Hooks.dll
Add-Type -AssemblyName System.Windows.Forms

$mh = New-Object LowLevelMouseHook
$frm = New-Object Form
#$mh.add_Down({Write-Host "test"}) //(a) does not work, but need this. Sometimes PS crashes
Register-ObjectEvent -InputObject $mh -EventName Down -Action {Write-Host "test"} // (b) does work
$mh.start()
$frm.showdialog()

Method (b)'s callback approach only works in a timely fashion while PowerShell is in control of the foreground thread, which is not the case here, because the $frm.showdialog() call blocks it. Therefore, method (a) must be used.

Steps to reproduce the bug

See example in description. More info about powershell handling events

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Platform

Windows Forms

IDE

Other

Additional context

Powershell

@Jomme5 Jomme5 added the bug Something isn't working label Nov 6, 2023
@Jomme5 Jomme5 changed the title Powershell: Add_xxx event handling does not work Powershell: add_xxx event handling does not work Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant