![how to get core out of handle how to get core out of handle](https://i.pinimg.com/736x/c2/04/73/c2047319afb2c2fed13bcf4a66e517e4.jpg)
I'm ignoring the fact that long running actions are generally a bad idea. While that action is processing, the user might cancel the request directly, or refresh the page (which effectively cancels the original request, and initiates a new one).
![how to get core out of handle how to get core out of handle](https://dam-assets.apps.travisperkins.group/9o9Oq/urfic-escutcheon-bathroom-handle-satin-nickel~GPID_1000251993_IMG_00.jpeg)
In this post, we'll assume you have an MVC action that can take some time to complete, before sending a response to the user. That's the default behaviour in MVC - even though the user has refreshed the browser, which cancels the original request, your MVC action won't know that the value it's computing is going to be thrown away at the end of it!
![how to get core out of handle how to get core out of handle](https://i.pinimg.com/originals/20/fe/35/20fe352711cdfa62b64137f949e4909a.png)
That's all well and good for the user, but what about your poor server? If the action method the user is hitting takes a long time to run, then refreshing five times will fire off 5 requests. Users expect a page to load pretty much instantly these days, and when it doesn't, a quick refresh can be very tempting. Have you ever been on a website where you've made a request for a page, and it just sits there, supposedly loading? Eventually you get board and click the "Stop" button, or maybe hammer F5 to reload the page. I'm not really going to cover any of the details of async, await, Tasks or CancellationTokens in this post, I'm just going to look at how you can inject a CancellationToken into your action methods, and use that to detect when a user has cancelled a request. This can be useful if you have long running requests that you don't want to continue using up resources when a user clicks "stop" or "refresh" in their browser. In this post I'll show how you can use a CancellationToken in your ASP.NET Core action method to stop execution when a user cancels a request from their browser.