Tom
Tom

Reputation: 8681

Convert type Task<IEnumerable> to type IEnumerable

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

Answers (2)

EgoPingvina
EgoPingvina

Reputation: 823

You have two paths:

  1. Use await before calling. In this case it will work asynchronously.

  2. Invoke .Result after calling. There your code will stop here and synchronously wait the result of the Task working.

Upvotes: 0

Corentin Pane
Corentin Pane

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

Related Questions