When should I use the Create LongRunning Task option?

I have a working Azure role that has three types of processes:

  • C # thread that reads from the database and writes to the input work queue (Task1)
  • A Java thread that reads from worker-input-queue runs and writes to worker-output-queue
  • C # stream, which reads from the work queue-output and writes to the database (Task2)

Task1 and Task2 work indefinitely and sleep if their respective queues are empty.

My code is as follows:

SpawnJavaProcesses(); Task.Factory.StartNew(Task1); Task.Factory.StartNew(Task2); while(true) { //do some trivial sporadic work Thread.Sleep(60*1000); } 

My questions:

  • Should I use the LongRunning task creation option when starting Task1 and Task2?
  • Is there a better way to implement what I'm trying to do here?
+6
source share
1 answer

If you have several threads that work for a long time, it is better to use the LongRunning parameter. By selecting this option, you will work in a thread outside the thread pool. This is also what was explained by Stephen Tub (from the Parallel Extensions team):

This is not a specific length in itself. If you create many tasks, LongRunning is not suitable for them. If you create one or two tasks that will persist for some time regarding the life of your application, then LongRunning is something to consider.

+6
source

All Articles