I have an Azure Worker Role that has three types of processes:
- C# thread that reads from the database and writes to worker-input-queue (Task1)
- Java thread that reads from worker-input-queue does work and writes to worker-output-queue
- C# thread that reads from worker-output-queue and writes to database (Task2)
Task1 and Task2 run indefinitely and sleep if their respective queues are empty.
My code looks like this:
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?
If you have a few threads that are long running it would be best to use the LongRunning option. By choosing this option you’ll be running in a thread outside of the thread pool. This is also something which was explained by Stephen Toub (from the Parallel Extensions team):