wcf - Exception handling on Tasks without Wait() -
Do not wait that what is the best way to handle a task exception ()? I read some blogs that used to talk about using ContinueWith because regular effort / hold work can not control exceptions.
Method 1:
Public class Service1: IService1 {public string GetData (int value) {var a = function Factor ThrowException; Return string Format ("You entered: {0}", value); } Private Woman Throw Exception () {try {Thread. Sleep (6000); Throw new logic options ("hello with exception"); } Hold (exception) {trace.writeline ("log in"); }}} Method 2:
Public class Service1: IService1 {public string GetData (int value) {var a = task. Resource. ThrowException; A.ContinueWith (c => {Trace.WriteLine ("Log In");} Task Continuation Options. Online On Fault); Return string Format ("You entered: {0}", value); } Private Wide Throwsection () {Thread. Sleep (6000); Throw new logic options ("hello with exception"); }} Method 1 and method 2 are doing the same thing?
Edit: Added code snippet for continuewith.
Work in both ways and they are identical. Choose why you like the most The advantage of one based on consistency is that you can control the error in an extension method (or some other central assistant).
Do you know that due to many reasons the process of IIS worker can disappear suddenly? In that situation the background work is lost. Or, the task defect but the error handler disappears.
Comments
Post a Comment