Given this piece of code:
someobject.ProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage);
How could I write the same thing in powershell, i used Register-Event but when i called the execute method on the object it just blocks the thread and you only see that the event has fired after the action is finished, I also tried to use Start-Job.
Any ideas?
Register-ObjectEvent should work:
See this TechNet article for more information about asynchronous event handling in PowerShell.
EDIT: As requested in comments, here is the code I used in my tests:
From there on, the signal times of the
Elapsedevents were printed to the console every half second until I managed to blind-type$timer.Stop().