0

I've an azure webjob where there is a function triggered by an azure queue

 public class Functions
 {
     public static void ProcessQueueMessage([QueueTrigger("scannedcodes")] string message, TextWriter log)
     {
         // do something
     }
 }

In this application there is also a timer with an interval of 5 minutes. When the Elapsed event of the timer is fired, I need to do something in the event handler that requires the method triggered by the queue is not running.

The true problem is that the queue trigger run 16 parallel threads, so each thread can process a queue message. So I need all threads aren't running to execute code into the timer event handler.

Matteo
  • 233
  • 3
  • 18

1 Answers1

0

I would take a look at the Interlocked Increment and Decrement methods to keep a running total of active processes. In the first line of your method, call Increment and in the last line call Decrement. When the timer event fires, check the current value of the counter and either wait for it to be 0 or do nothing.

https://msdn.microsoft.com/en-us/library/system.threading.interlocked_methods(v=vs.110).aspx

Justin Patten
  • 1,059
  • 6
  • 16