22.2. Event-Handling Mechanics

An event in .NET is usually given a delegate, and the sender invokes that delegate when it raises the event. Many people are used to that paradigm and would probably expect that that would be the case with PSEventing. Maybe we can just pass a script block as an event handler—not so fast! PowerShell lacks good threading support for scripts, and firing an event from a foreign piece of code may be dangerous from a concurrency point of view.

That is why PSEventing takes a slightly different approach: it creates the abstraction of a global event queue. All access to the event queue will be synchronized to protect us from concurrency-related problems. The rules according to which the queue is filled are stored in the ...

Get Pro Windows PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.