Lets assume that I have a several layers:
- Manager that reads data from a socket
- Manager that subscribes to #1 and takes care about persisting the data
- Manager that subscribes to #2 and takes care about deserialization of the data and propagating it to typed managers that are insterested in certain event types
- WPF Controllers that display the data (are subscribed to #3)
As of right now I use
TaskFactory.StartNew(()=>subscriber.Publish(data)); on each layer. The reason for this is that I don't want to rely on the fact that every manager will do his work quickly and that ex. Socket manager is not stuck.
Is this a good approach?
Edit Let's say that Socket manager receives a price update There are 10 managers subscribed to Socket manager so when Socket manager propagates the message .StartNew is called 10 times.
Managers #2,#3 do nothing else but to propagate the message by .StartNew to a single subscriber
So ultimately per 1 message from socket 30x .StartNew() is called.
.StartNew( )lines do you have in total that are running at the same time?Task.Runis a newer way of running Tasks. At the time we didTaskFactory.StartNew, there was noTask.Run, but now it's there! Besides if you read the link carefully you see that the accepted answer confirms my claim.