Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As a quick solution I can suggest to keep a list of delegates with the method you want to invoke on each timer tick. So on user action you just add the method you want to invoke. If the parameters must be unique for each user call, you might do something like in the following code:</p> <pre><code>// This is the class handling the timer ticks public class ActionExecutor : IDisposable { private Timer timer; private IList&lt;Action&gt; actionsList = new List&lt;Action&gt;(); public ActionExecutor() { // choose the interval as suits you best, or use // constructor argument timer = new Timer(1000); timer.Elapsed += OnTimerTick; timer.AutoReset = true; timer.Start(); } void OnTimerTick(object sender, ElapsedEventArgs) { lock(actionsList) { foreach(Action a in actionsList) { a(); } actionsList.Clear(); } } public void AddAction(Action a) { lock(actionList) { actionList.Add(a); } } public void Dispose() { // we must stop the timer when we are over if (timer != null) { timer.Stop(); } if (actionList != null) { actionList.Clear(); } } ~ActionExecutor() { Dispose(); } } </code></pre> <hr> <pre><code>//handling user click in your application void OnUserClick() { // built the specific notification request NotificationMessageRequest request = ... actionExecutor.AddAction(() =&gt; SendNotificationMessage(request)); } </code></pre> <p>In the code above, you must make sure you are using the same <code>ActionExecutor</code> instance where you handle the user actions. Notice the synchronization with the locks - timers usually run in separate thread than the thread adding the action. If you are speaking of a web application, then each user is running int his/her own thread, so multiple users at once will also add concurrency. Also, you may have to add appropriate error handling, as I have omitted that part for brevity.</p> <hr> <p><strong>Update</strong></p> <p>As suggested in comments, you might benefit from using a different collection than a list to hold the actions. It depends on the actual needs of your scenario.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload