WCF operation Async Operation + IO

What is the benefit of writing the following WCF service operation using Async CTP?

Will Task.Factory.StartNew in any case block thread threadpool during a long queue?

public Task<string> SampleMethodAsync(string msg) { return await Task.Factory.StartNew(() => { return longRunningIOOperation(); }); } 

Is there a better way to write this so that we can use I / O completion streams?

+1
source share
2 answers

You will need the asynchronous operation longRunningIOOperation . As long as any operation in your code blocks a thread, some thread will be blocked, either threadpool or the one in which your operation was called. If your operation is asynchronous, you can write something similar to the code below.

 public Task<string> SampleMethodAsync(string msg) { var tcs = new TaskCompletionSource<string>(); longRunningIOOperationAsync().ContinueWith(task => { tcs.SetResult(task.Result); }); return tcs.Task; } 
+1
source
Finally, I realized how it works. I installed .net FX4.5 and it worked like a charm.

In my scenario, service A makes a call to service B like this.

 public class ServiceA : IServiceA { public async Task<string> GetGreeting(string name) { ServiceBClient client = new ServiceBClient(); return await client.GetGreetingAsync(); } } 

client.GetGreetingAsync () takes 10 seconds to process. My misunderstanding is a service request. The request will not be blocked by a call to GetGreetingAsync ().

Can you explain how this is implemented by WCF backstage or point me to some documentation to understand how it all works from the perspective of WCF?

0
source

Source: https://habr.com/ru/post/1385060/


All Articles