PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are developing an application that uses multiple asynchronous tasks to optimize performance. The
application will be deployed in a distributed environment.
You need to retrieve the result of an asynchronous task that retrieves data from a web service.
The data will later be parsed by a separate task.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
Option A

B.
Option B

C.
Option C

D.
Option D

10 Comments on “Which code segment should you use?

          1. didii says:

            Agree. Depends on how the return statement is formatted in GetData(). If it returns a Task object it’s A, if it returns a string it’s B.

            The following are both correct:

            public Task GetData() => Task.FromResult(“some data”);
            and
            public async Task GetData() => “some data”;




            3



            0
          2. ivannathan says:

            Dude, it already returns Task class, which is already asyncronous and doesnt need async keyword.

            You can get the result from Task by using await or getting Task.Result

            The correct answer is A.

            Please read about tasks and TPL – many developers doesn’t know the correct answer for this simple question.




            2



            0

Leave a Reply