Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need comprehensive C# System.Threading.Tasks example

I've been trying to figure out how to use System.Threading.Tasks to asynchronously invoke a synchronous WCF method while supporting cancellation, error handling, result-return and multiple continuations.

I've come across a number of incomplete demos but they all seem to fall a bit short. As an example I can't use cooperative cancellation since all of my WCF methods are atomic and relatively long lived.

like image 533
Louis S. Berman Avatar asked Nov 05 '22 11:11

Louis S. Berman


1 Answers

I would consider an alternate option - generate the WCF client interface with asynchronous methods. This will allow you to make all WCF service calls asynchronously (from the perspective of the client application), which will allow you to support cancellation, error-handling, result-return, etc.

The benefit is that you won't be blocking a thread on the worker thread pool (like System.Threading.Tasks will), and you don't have the worry of trying to figure out how to cancel a synchronous WCF call in your worker thread.

Is there a reason that you must make a synchronous WCF call?

like image 172
Sam Avatar answered Nov 14 '22 23:11

Sam