Member-only story
TIPS AND TRICKS
How to Cancel a Running Process in a Separate Request/Command in .NET C#
Learn how to cancel an already running process in a separate request in .NET C#

One of my friends was working on a unique project where he needed to be able to cancel a long running process but on a separate request. Weird? maybe but it happened. Let me tell you more…
He was working on a Web Application with heavy 3D modelling. This application was supposed to be used for building 3D models for a certain product and the end user at some point should have been able to download this model in a certain format.
However, the modeling process itself is so heavy and requires a lot of processing. That’s why the end user was supposed to provide some input, trigger the modelling process and at some point he was supposed to get an email when the model is ready for download.
Up till now, it’s ok. But, if the end user decides to apply some changes on the inputs, he can start a new modelling process, but what about the already running one? Is it wise to just keep it running on the server???

Step By Step
Ok, what I am going to explain here is not rocket science. However, let’s take it a step by step.
First, let me point out the following:
- Some best practices would be ignored/dropped in order to drive the main focus to the other concepts this article is about.
- We will not create a whole Web Application as this would include a lot of distractions. We would just use Console and Windows Forms apps.
- The code included into this article is for demonstration and explanation only. Before going to your production code, you need to apply some refactoring and…