c# - Prevent Task.ContinueWith on exception -


i trying prevent task continuing if first part fails.

my code looks that:

task listener = task.factory.startnew(openconnection).continuewith((t) => listenfornumber());      void openconnection()     {         try         {            //stuff         }         catch         {           //morestuff         }     }      void listenfornumber()     {        //even more stuff     } 

now listenfornuber() should not executed if openconnection() enters catch block

i tried continuewith((t) => listenfornumber(),taskcontinuationoptions.notonfaulted);

but no success, help? :(

thanks

taskcontiuationoptions.notonfaulted have no effect unless method has faulted, i.e. exception thrown during execution unhandled.

in catch block, should re-throw exception (and preserve stack trace) using throw; statement after you've performed work (some clean-up maybe) - otherwise exception won't thrown again, method not considered 'faulted'.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -