As the title says, I call a method which starts to load from a database.
If a specific event is raised, I would like to prematurely exit that method without waiting for it to finish loading.
Edit: The method in question runs on the UI thread
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no way to (cleanly) destructively cancel a method from outside of that method.
Cancellation in the .NET Framework is typically a cooperative model. This means you’re event would request a cancellation, and the method would, in turn, occasionally check for whether it should cancel and then exit cleanly.
This is handled via the
CancellationTokenandCancellationTokenSourcetypes within the framework. For details, see the topic about Cancellation on MSDN.