Need comprehensive C# System.Threading.Tasks example
I've been trying to figure out开发者_JAVA百科 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.
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?
If you explained what your doing a bit more it might help.
However you seem to be saying you want an async version of a syncronous call and this isn't what Tasks is about.
Task based processing is about making an async call look like a syncronous call. Not act like it just the code look like thats the way it works.
精彩评论