Parallel programming to make multiple async requests -Dynamics Plugins.

Ankaprasad
Posted by Ankaprasad under C# category on | Points: 40 | Views : 530
 

int recCount=100;

// The below line of code will make 100 async requests to the CreateRecord () Method //

Parallel.For(0, recCount, (i) => CreateRecord(i, _service, tracingService));

public void CreateRecord(int i,IOrganizationService _service, ITracingService trace)
{
Entity account = new Entity("new_child");

account.Attributes["new_name"] = "Name " + i.ToString();
account.Attributes["new_number"] = i;
trace.Trace(i.ToString());
Guid id = _service.Create(account);
}

//List<int> items = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,50 };
// Parallel.ForEach(items, (i) => CreateRecord(i, _service, tracingService));

Comments or Responses

Login to post response