You see any pitfalls or problems when creating two separate tasks for querying Oracle db and querying Active Directory, and then waiting for both.
Below is a very simple example. Essentially, we have an employee object that is created from pieces of information from AD and from an Oracle database. (called sequentially)
var partialEmployeeA=ActiveDirectoryLookup(employeeID); var partialEmployeeB=OracleDBLookup(employeeID); var finalEmployee=Merge(partialEmployeeA,partialEmployeeB);
At this point, the Employee object was created and assembled along with both requests and can be used. This worked without problems, but if each of these challenges were its own task, would you see any problems in terms of scaling? (excluding any other obvious code issues)
Employee partialEmployeeA; Employee partialEmployeeB; var t1 = Task.Run(() => { partialEmployeeA=ActiveDirectoryLookup(employeeID); }); var t2 = Task.Run(() => { partialEmployeeB=OracleDBLookup(employeeID); });, Task.WaitAll(t1, t2); var finalEmployee=Merge(partialEmployeeA,partialEmployeeB);
I did some testing with the stopwatch class, and the version of Task returned faster every time (avg: 100-120ms vs 200-250 ms) and had no problems, but was not sure how it scales in a multi-core system, I did not do much with TPL but I was curious about this approach.
source share