New Posts New Posts RSS Feed: Best way to handle a cancelled task
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Best way to handle a cancelled task

 Post Reply Post Reply
Author
JohnBloom View Drop Down
Groupie
Groupie
Avatar

Joined: 30-Nov-2010
Location: Topeka, KS
Posts: 95
Post Options Post Options   Quote JohnBloom Quote  Post ReplyReply Direct Link To This Post Topic: Best way to handle a cancelled task
    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
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
JohnBloom View Drop Down
Groupie
Groupie
Avatar

Joined: 30-Nov-2010
Location: Topeka, KS
Posts: 95
Post Options Post Options   Quote JohnBloom Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down