title: Common approach to cancel different asynchronous operations
body: <p>I have somewhat non-trivial task and I'd appreciate to hear from you, how to solve it better. In a nutshell, this is about managing long-running tasks of different nature. While I'm doing this for Windows Phone, I feel like some general principles could be applied here, based on C# and .NET standard approaches.</p>
  
  <p>My application is mainly built around different service classes, which handles data from the cloud, GPS, commercial transactions, authentication, etc. All the services are owned by our team. Services are used inside view models, but API in different services is currently of different fashion. Somewhere it's async/await, somewhere it's event-based (like in positioning, where I need to update geo coordinate constantly). </p>
  
  <p>Now I've started to look into the issue of application activation/deactivation, and I would like to handle this in a common way in all my view models. One of the main thing is cancellation of current async operations when app is closing or when user navigates to another page. I want to put the code related to that into something like BaseViewModel, to avoid code duplication. However this means that I need to handle cancellation in all view models uniformly.</p>
  
  <p>Here comes the challenge. For example, async/await stuff could be cancelled by CancellationToken. I could collect all the cancellation tokens in BaseViewModel, and use them all when needed. However, this will not work with event-based asynchrony. Of course one could delegate concrete cancellation operation to child view model, via virtual function call. But I want to move as much as possible code to the BaseViewModel. </p>
  
  <p>So, is there a way to unify cancellation of Tasks and event-based asynchrony?</p>