How to stop a function in middle in C#? RRS feed

  • Question

  • 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. That would take at least 10 seconds to complete. I want to  stop that method in the middle at anytime. I know that I can use a flag like shouldStop = true;. But if I prefer to use that, I would have to use it after every statement of that function, which does not seem to be a proper solution.

    Any help is greatly appreciated. (It is an uwp C# app for windows 10 store.)
    • Edited by Bhadurudeen Tuesday, November 24, 2020 1:14 PM
    Tuesday, November 24, 2020 1:12 PM

All replies