Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Killing a .NET 4 Task?

Can I kill a .NET 4.0 Task object with some method like we could with the old and dangerous Thread.Abort() as discussed in the SO thread (pun intended and save the kittens!)

Kenny

like image 229
kenny Avatar asked Nov 03 '22 23:11

kenny


1 Answers

The Task class is designed, and intended, to use the new Cooperative Cancellation model of .NET 4 instead of relying on a destructive "abort" style of cancellation.

There is no direct way to cancel a Task (like Thread.Abort(), though that's very bad to use in any case), but there is an entire framework in place to provide the tooling to request that the Task cancel itself.

like image 73
Reed Copsey Avatar answered Nov 15 '22 07:11

Reed Copsey