Reputation: 8681
I have the following expression which is of the type Task<IEnumerable<PendingApprovalUserChangeRequest>>
and I need to convert it to IEnumerable<PendingApprovalUserChangeRequest>
. How do I do that ?
Task<IEnumerable<PendingApprovalUserChangeRequest>> pendingChangeRequest = service.GetPendingChangeRequest();
Upvotes: 1
Views: 2286
Reputation: 823
You have two paths:
Use await
before calling.
In this case it will work asynchronously.
Invoke .Result
after calling. There your code will stop here and synchronously wait the result of the Task
working.
Upvotes: 0
Reputation: 4943
You can await
it in an async
method:
IEnumerable<PendingApprovalUserChangeRequest> result = await pendingChangeRequest;
You can read more about asynchronous programming here.
You should also read these best practices from MSDN if you have to introduce async
in your codebase (which seems to be your case).
Upvotes: 5