views:

48

answers:

2

I have written a simple class that works with a UIElement and an action to invoke. Whenever the action is invoked, it puts the action in dispatcher queue, if its not already there. I use it to reduce number of calls.

class NoNameClass
{
 // has element and action in its ctor.

 void NoNameMethod()
 {
  if (!inQueue)
  {
   inQueue = true;
   element.Dispatcher.BeginInvoke(()=> 
    {
      inQueue = false;
      action();
    }
  }
 }
 bool inQueue;
}

Can you please suggest a name for this class and the method? Thanks

+1  A: 

As name for the class i would define "DispatcherAction" and the method i would call "Queue".

Maybe you can add the adjectives "deferred" or "delayed" to the names, cause it´s up to the Dispatcher when he executes the action. So it´s clear that the actions will be executed not immediately.

Update: For the case that actions are discarded, when they are already in the queue, i would name the methode "TryQueue" and return a boolean. The method returns "true" if the action is queued, "false" if the action is discarded, because it´s already queued.

Jehof
I used the name Enqueue for method, but to reviewer it seems a misnomer because action is not always queued. Its discarded if already in queue.
Nitesh Chordiya
A: 

How about a DispatchManager class with a Start() method?

PabloC