How to stop a function in middle in C#?

MG Bhadurudeen 626 Reputation points

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.

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.
10,164 questions
0 comments No comments
{count} votes