How to stop a function in middle in C#?

MG Bhadurudeen 626 Reputation points
2020-11-24T13:08:23.667+00:00

It may be a basic question, But I could not find an answer for that.

I have a function having some sync and async statements. It would take at least 10 seconds. I want to stop that method in the middle at any time. I know that I can use a flag like shouldStop. But if I prefer to use that, I would have to use it after every statement, which does not seem to be a proper solution.

Any help is greatly appreciated.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.