I use TPL in my wp7 application for some background manipulations.
The application launches the task:
var task =
Task.Factory.StartNew(
() =>
{
// Some sort of operations
});
After that, the application launches user interface updates:
task.ContinueWith(
obj =>
{
},
new CancelationSource.Token,
TaskContinuationOptions.None,
TaskScheduler.FromCurrentSynchronizationContext());
But there's a problem. If I click the back button to close the application and the task is not finished yet, the application throws an AggregateException with an internal exception ThreadAbortException. As I understand it, this is because the reverse flow ended incorrectly.
How can I prevent this? Maybe there is some right way to cancel the task?
I have only one idea - to catch this exception and pretend that nothing happened. Correctly?