Your task should complete ICancelableTask . This is a very simple interface added in 4.0.
Basically you just add the Cancel () method. He should be ready to call in another thread at any time and return immediately. Then your task should return from Execute. Usually you set the boolean flag inside Cancel (). Then inside your task, as a rule, you process each input in turn - for example, copying one file after another - and at each iteration check the flag; if true, break free. It doesn't matter if you return true or false from Execute in this context.
If you exit ToolTask - if your task generates a tool, it is highly recommended that you do this, since it saves a lot of code, processes asynchronous logs and other things - then it already processes Cancel automatically. When “Cancel” occurs, she kills the tool that he spawned, and all his children. The tasks of the C ++ command in some cases override this default behavior, so their compiler / linker takes a few seconds to clear their half-written outputs before returning.
(Trivia: when I first implemented this in MSBuild, I accidentally made VS bluescreen a field occasionally. It was almost sent to VS10 beta, but it was detected just in time. Bluescreen was because the logic for determining the process tree was wrong and will sometimes kill system process unfortunately.
Dan
cheerless bog
source share