The main purpose of Rx is not to provide an abstraction over events. This is just one of its outcomes. Its primary purpose is to provide a composable push model for collections.
The reactive framework (Rx) is based on IObservable<T>
being the mathematical dual of IEnumerable<T>
. So rather than "pull" items from a collection using IEnumerable<T>
we can have objects "pushed" to us via IObservable<T>
.
Of course, when we actually go looking for observable sources things like events & async operations are excellent candidates.
The reactive framework naturally requires a multi-threaded model to be able to watch the sources of observable data and to manage queries and subscriptions. Rx actually makes heavy use of the TPL to do this.
So if you use Rx you are implicitly using the TPL.
You would use the TPL directly if you wish direct control over your tasks.
But if you have sources of data that you wish to observe and perform queries against then I thoroughly recommend the reactive framework.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…