How it works...

What we need to keep in mind here from the code we created is that there is ObserveOn and Subscribe. You should not confuse the two. In most cases, when dealing with schedulers, you will use ObserveOn. The ObserveOn method allows you to parameterize where the OnNext, OnCompleted, and OnError messages run. With Subscribe, we parameterize where the actual subscribe and unsubscribe code runs.

We also need to remember that Rx uses the threading timers (System.Threading.Timer) as a default, which is why we encountered the cross-thread violation earlier. As you saw though, we used schedulers to parameterize which timer to use. The way schedulers do this is by exposing three components. These are as follows:

  • The scheduler's ability ...

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.