Article : Delayed Delegate Invoker

Here’s my latest article that discusses a simple utility class that lets you queue up delegates and then execute them at a later time in a first-in first-out order. I wrote this when I had a situation where I was doing some rather complex processing based on property changed event notifications, and I found that some of the earlier notifications were going unhandled because the processing code had not completed a stable initialization at that point. So I queued up my various event handlers and then invoked them once I was sure it was safe to do so. Other uses I can think of include using this class as a macro recorder – just queue up all your mouse and keyboard actions, and invoke them during playback.

Advertisements

One thought on “Article : Delayed Delegate Invoker

  1. You can solve the dissimilar arguments problem better by having the user of your class use closures and anonymous methods.

    Instead of taking Delegate, you could take a delegate of type delegate void Action(), and it can be used like

    delayedInvoker.Add(()=> this.Add(text));

    This way, there is no possibility of runtime errors because of argument mismatch, and it looks cleaner IMO.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s