Print Page | Close Window

Best way to handle a cancelled task

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3940
Printed Date: 22-Oct-2019 at 11:32pm


Topic: Best way to handle a cancelled task
Posted By: JohnBloom
Subject: Best way to handle a cancelled task
Date Posted: 24-Jan-2013 at 7:53am
So I am still getting used to the new DevForce/Cocktail stuff. One thing that has been happening is that when a user clicks cancel on a dialog the Task throws a task cancelled exception. I read somewhere to handle cancelled tasks with a try/catch. I did that twice and realized that was bad advice. I have too many dialogs and I am not about to litter my code with try/catch blocks. 

I looked at the temphire app and I didn't really see how it was handling the cancel. I am guessing it is in how you implement it. When I implement it this way:
await _DialogManager.ShowDialogAsync(vm.Start(ServiceInstance.ID), DialogButtons.OkCancel);
 I get exceptions. What do I need to change?


-------------
-John Bloom



Replies:
Posted By: smi-mark
Date Posted: 24-Jan-2013 at 8:26am
Hi John,

If you look in TempHire in the ErrorHandler class you will see it checks for TaskCanceledExceptions and simply ignores it. This way you don't have to write try/catch code everywhere.


Posted By: JohnBloom
Date Posted: 24-Jan-2013 at 9:10am
Thanks Mark that did the trick. I should have known to look in the error handler class...

-------------
-John Bloom



Print Page | Close Window