Webservice Foreach Concurrent Call

We have implemented an application in which we need to process an incoming batch. for example, a request set of a certain type of object must be sent to a specific web service to process it.

We performed the following snippet to do this. you need your help / guide if there are any pitfalls on the same

var options = new ParallelOptions { MaxDegreeOfParallelism = 10 };

Parallel.ForEach(request, options, currentRequest =>
{
    ProcessedRequest processedRequest = null;
    try
    {
        currentRequest.DBSave = true;

        processedRequest = CommunicateToService(currentRequest);

    }
    catch (Exception ex)
    {

        ExceptionManager.HandleException(ex);
    }
});

Inside the CommunicateToservice method, we will call the service and send the request and receive the response object and save about 10-15 tables in MS SQL DB. The whole method is wrapped using an AggregateException.

Data entry is required on how to determine the value of MaxDegreeOfParallelism.

0
source share
1 answer

IO- . , . , .

, DOP, .

+2

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


All Articles