Project Description - ActionScheduler

(First of all: Sorry for my bad english, I'm from Germany)

Have you ever build a real big UI with WPF, which is doing a lot of stuff when the user just clicks an item or is browsing through a list of data?

Here the ActionScheduler will help you a lot!

 

ActionScheduler does the following for you:

  • It Runs a Action in the Backgound or on the Main UI thread.
  • It can delay the execution of the action
  • It can start a action on a different thread or on the main UI Thread after the first action is completed.
  • It is canceling a scheduled action if the same action is scheduled again.
  • It can even cancel multiple scheduled actions of a certain scopeKey

And of course: ActionScheduler is thread save!

So you can easily build complex multithreaded apps.

 

Usage:

  • ActionScheduler.ScheduleAction(someAction); 
  • ActionScheduler.ScheduleAction(() => someActionWithParams(arg1, arg2)); 
  • ActionScheduler.ScheduleAction(someAction, runOnGuiThread: true); 
  • ActionScheduler.ScheduleAction(someAction, delayInMilliseconds: 500); 
  • ActionScheduler.ScheduleAction(someAction, onCompleted: someOtherAction);
  • ActionScheduler.ScheduleAction(someAction, onCompleted: someOtherAction, runOnCompletedOnGuiThread: true);
  • ActionScheduler.ScheduleAction(someAction, scopeKey: "yourScopeKey");
  • ActionScheduler.ScheduleAction(someAction, actionKey: "yourActionKey"); 

 

Where to use it:

Say you have a list of products. If the user clicks a product you will show various details, like produkt details, images, sales statistics and so on. To show all Details, even with a very good machine you code needs 800 ms. So far so good. 800 ms is quite good for so much data. But now the user wants to use the keyboard and presses the down arrow key to browse through the list of products. Bad idea, because it takes 800ms to show the details the result of browsing down is not really great.

 

Solution:

Split your UI update in many small units of code and run them with a little delay in the background (if possible) and in the main UI thread with a low dispatcher priority (lower than a keyboard action). And cancel not needed actions (If the user has moved already 10 products down the list you don't have to load the details of the 9 products before any more... To do this, use ActionScheduler and a scopeKey for every refresh and cancel the not needed scops or run the refresh on the same method in the same class ( = Your details ViewModels Refresh  Method) so ActionScheduler will remove not needed actions autmatically.

 

Have fun using the code. It is used and tested quite good in some real world application.

Nice greetings,
Markus

Last edited Nov 23, 2013 at 9:43 PM by mahop, version 6