Visual Programming MCQs with Answers
Practice important Visual Programming MCQs with answers and explanations.
Multiple Choice Questions
Q621: What is the purpose of TaskCompletionSource<T>.SetResult()?
- A: It sets the result of the task and completes it
- B: It initiates the creation of a new task
- C: It marks the task as failed with an exception
- D: It starts a new thread to handle the task
View Answer
A
Q622: What will be the output of the following code: Task<int> task = Task.Run(() => { Thread.Sleep(5000); return 42; });?
- A: The output will be 42 printed after a delay of 5 seconds
- B: The output will be 0 printed immediately
- C: The output will be an exception thrown after 5 seconds
- D: The output will be 42 printed immediately
View Answer
A
Q623: In the context of threading, what is the main use of the Thread.CurrentThread.IsThreadPoolThread property?
- A: To determine if the current thread is a thread pool thread
- B: To check if the thread has been created manually
- C: To identify if the thread has completed execution
- D: To verify if the thread is running in the background
View Answer
A
Q624: What is the effect of calling Task.Wait() on a task that has been completed?
- A: It blocks until the task completes, but if already completed, it returns immediately
- B: It restarts the task from the beginning
- C: It cancels the task if it is already completed
- D: It does not affect the task if it is completed
View Answer
A
Q625: How does SynchronizationContext facilitate updating the UI from background threads?
- A: It marshals the update requests to the UI thread
- B: It creates new UI threads for each update request
- C: It prevents the UI thread from being blocked during updates
- D: It automatically handles UI thread synchronization for background tasks
View Answer
A
Q626: What is the primary advantage of using asynchronous programming in C#?
- A: It allows tasks to run without blocking the main thread and improves responsiveness
- B: It automatically manages thread creation and destruction
- C: It ensures all tasks are executed in parallel without using any threads
- D: It simplifies code by eliminating the need for any form of concurrency
View Answer
A
Q627: How does Task.Run handle CPU-bound tasks compared to I/O-bound tasks?
- A: It efficiently handles CPU-bound tasks by using threads from the thread pool
- B: It directly handles I/O-bound tasks without creating new threads
- C: It avoids thread creation for CPU-bound tasks by using asynchronous operations
- D: It cannot be used for CPU-bound tasks and is only suitable for I/O-bound tasks
View Answer
A
Q628: What does the await keyword do in asynchronous programming?
- A: It pauses the execution of a method until the awaited task completes
- B: It immediately executes the awaited task in a new thread
- C: It makes the method synchronous by blocking until the awaited task is completed
- D: It executes the awaited task in parallel with other tasks
View Answer
A
Q629: How can the TaskCompletionSource<T> be used in asynchronous programming?
- A: It provides a way to manually control the completion of a task, including setting results and handling exceptions
- B: It simplifies the creation of tasks by automatically managing their lifecycle
- C: It ensures that tasks are completed in a specified order
- D: It handles task exceptions and continuations without requiring any additional code
View Answer
A
Q630: In the example provided, what does Task.Run(() => displayprimecounts()); do?
- A: It executes the displayprimecounts method asynchronously on a thread pool thread
- B: It synchronously calls displayprimecounts on the main thread
- C: It delays the execution of displayprimecounts by 5 seconds
- D: It starts a new thread for each prime count calculation
View Answer
A