0

Assuming I have a very long running operation that does not contain any loop, I mean the nature of the operation is long running without any recursion and repetition. In this case if I use the CancellationToken type to throw a cancelling exception or a Boolean Flag for "Safely" cancelling the task, the token or flag can never be reached.

Now the only goal would be to break the running task regardless of whether aborting is a good or bad approach. When using threads, the abort method is present (I'm not interested in discussing about it's disadvantages as I'm already aware of it), but when it comes to the Task type, I don't see it there. And assuming my Task has to return a value, then threads are out of questions.

What is the safest and most efficient way to implement this.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Arnold Zahrneinder
  • 4,788
  • 10
  • 40
  • 76

1 Answers1

-1

You can kill the process,

process.Kill();

Cancellation task or aborting task is never promised regardless of what documentation says.

OR

You can start your tasks in a thread and then use thread.abort();.

I am afraid you don't have much choice available here.To be more sure, you need to provide context.

enter image description here

Mathematics
  • 7,314
  • 25
  • 77
  • 152