exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 2 question 48 discussion

Actual exam question from Microsoft's 70-483
Question #: 48
Topic #: 2
[All 70-483 Questions]

You are implementing a new method named ProcessData. The ProcessData() method calls a third-party component that performs a long-running operation to retrieve stock information from a web service.
The third-party component uses the IAsyncResult pattern to signal completion of the long-running operation.
You need to ensure that the calling code handles the long-running operation as a System.Threading.Tasks.Task object.
Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

  • A. Call the component by using the TaskFactory.FromAsync() method.
  • B. Create a TaskCompletionSource<T> object.
  • C. Apply the async modifier to the method signature.
  • D. Apply the following attribute to the method signature: [MethodImpl(MethodImplOptions.Synchronized)]
Show Suggested Answer Hide Answer
Suggested Answer: AB 🗳️
A: TaskFactory.FromAsync Method -
Creates a Task that represents a pair of begin and end methods that conform to the Asynchronous Programming Model pattern. Overloaded.
Example:
TaskFactory.FromAsync Method (IAsyncResult, Action<IAsyncResult>)
Creates a Task that executes an end method action when a specified IAsyncResult completes.
B: In many scenarios, it is useful to enable a Task<TResult> to represent an external asynchronous operation. TaskCompletionSource<TResult> is provided for this purpose. It enables the creation of a task that can be handed out to consumers, and those consumers can use the members of the task as they would any other. However, unlike most tasks, the state of a task created by a TaskCompletionSource is controlled explicitly by the methods on TaskCompletionSource. This enables the completion of the external asynchronous operation to be propagated to the underlying Task. The separation also ensures that consumers are not able to transition the state without access to the corresponding TaskCompletionSource.
Note:

System.Threading.Tasks.Task -
Represents an asynchronous operation.

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
slargollo
Highly Voted 5 years, 5 months ago
For me, it's A and C.
upvoted 15 times
slargollo
5 years, 5 months ago
Although one can use TaskCompletionSource, TaskFactory.FromAsync is the best way to create tasks from APM style API (IAsyncResult). Anyway, it doesn't make sense to use both. http://hamidmosalla.com/2018/05/27/task-run-vs-taskcompletionsource-vs-task-factory-fromasync/
upvoted 4 times
...
...
slobex
Highly Voted 5 years, 1 month ago
For me it is A and B ( both schould presents part of a complete solution) https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskcompletionsource-1?view=netcore-3.1
upvoted 6 times
noussa
4 years, 5 months ago
From the link, you provided there is no use of the FromAsync and anyway it doesn't make sense to use FromAsync when you didn't apply async to your task.
upvoted 1 times
...
...
ajpatonline
Most Recent 4 years, 5 months ago
(Each correct answer presents part of the solution. Choose two.) so A and B
upvoted 1 times
Pedroalmeida25
4 years, 5 months ago
Hmm.. Doesn't it mean that together they form a solution. It doesn't make sense if it's like you are saying. A/C or B/C
upvoted 1 times
...
...
HgstExam
4 years, 9 months ago
I don't understand why A,B are correct, because one or the other can be used to solved this problem not both, someone please help.
upvoted 4 times
noussa
4 years, 5 months ago
Same here it should be A, C or B, C but not AB
upvoted 1 times
noussa
4 years, 5 months ago
To make sure that it should be AC or BC but NEVERRR AB. This a cheat sheet for async methods and tasks and you will find that FromAsync and TaskCompletionSource<T> CANNOT be used together. be aware guys cause they do the same job. https://gist.github.com/jonlabelle/841146854b23b305b50fa5542f84b20c
upvoted 2 times
...
...
...
BurgSharp
5 years ago
I think A, C return await Task.Factory.FromAsync link: https://gist.github.com/emoacht/aa1f919a0dc6b6906d41
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...