I need to make two wcf calls to buildup a model
[SecurityOperationBehavior]
public Response1 Func1(Request1 req)
{
}
[SecurityOperationBehavior]
public Response2 Func2(Request2 req)
{
}
I understand I need to use TaskCompletionSource to wait until both the calls to be finished.
public FullResult GetResult(int id)
{
Request1 req = new Request1 ();
req.id = id;
Request2 req2 = new Request2 ();
req2.id = id;
var taskCompletions = new[]
{
new TaskCompletionSource<object>(),
new TaskCompletionSource<object>()
};
var tasks = new[] { taskCompletions[0].Task, taskCompletions[1].Task };
System.Threading.Tasks.Task.Factory.StartNew(()=>Func1(req );
System.Threading.Tasks.Task.Factory.StartNew(()=>Func2(req2 );
System.Threading.Tasks.Task.WaitAll(tasks);
//the following is what I want to do. The results of the
//two service calls will be contained in the the full result
FullResult result = new FullResult();
result.first = tasks[0].Result;
result.second = tasks[0].Result;
return Result;
}
Problem:
How do I set the results after both the service calls are finished?
There is no need for task completion sources at all here. Just wait on the results of
Task.StartNew: