Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Follow publication

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#

Ahmed Tarek
Level Up Coding
Published in
9 min readDec 19, 2021

--

Learn how to cancel an already running process in a separate request/command in DotNet (.NET) CSharp (C#)
Photo by Markus Winkler on Unsplash

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???

Learn how to cancel an already running process in a separate request/command in DotNet (.NET) CSharp (C#), https://medium.com/@eng_ahmed.tarek
Photo by Jukan Tateisi on Unsplash

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:

  1. Some best practices would be ignored/dropped in order to drive the main focus to the other concepts this article is about.
  2. 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.
  3. 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…

--

--

Written by Ahmed Tarek

Software Engineer 👨‍💻 | .NET dotnet C# csharp c-sharp | Website: https://www.developmentsimplyput.com | LinkedIn: @atarekhasan

Responses (1)

Write a response