Chapter 7 Flashcards

1
Q
  1. You are a developer at company xyx. You have been asked to improve the responsiveness of your WPF application. Which solution best fits the requirements?
    a. Use the BackgroundWorker class.
    b. Use the LongRunningMethod class.
    c. Run the method in the UI thread.
    d. Use the WorkInBackground class.
    e. None of the above.
A

a. Use the BackgroundWorker class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. How do you execute a method as a task?
    a. Create a new Task object, and then call the Start method on the newly created object.
    b. Create the task via the Task.Run method.
    c. Create the task via the Task.Factory.StartNew method.
    d. All the above.
    e. None of the above.
A

d. All the above.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. Which of the following is not a locking mechanism?
    a. Monitor
    b. Semaphore
    c. Mutex
    d. async
A

d. async

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. How can you schedule work to be done by a thread from the thread pool?
    a. You create a new object of type ThreadPool, and then you call the Start method.
    b. You call the ThreadPool.Run method.
    c. You call the ThreadPool.QueueUserWorkItem method.
    d. You create a new thread and set its property IsThreadPool to true.
    e. You call ContinueWith on a running thread from the thread pool.
A

c. You call the ThreadPool.QueueUserWorkItem method.

d. You create a new thread and set its property IsThreadPool to true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. Which of the following are methods of the Parallel class?
    a. Run
    b. Invoke
    c. For
    d. ForEach
    e. Parallel
A

b. Invoke
c. For
d. ForEach

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. Which method can you use to cancel an ongoing operation that uses CancelationToken?
    a. Call Cancel method on the CancelationToken
    b. Call Cancel method on the CancelationTokenSource object that was used to create the CancelationToken
    c. Call Abort method on the CancelationToken
    d. Call Abort method on the CancelationTokenSource object that was used to create the CancelationToken
A

b. Call Cancel method on the CancelationTokenSource object that was used to create the CancelationToken

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. Which method would you call when you use a barrier to mark that a participant reached that point?
    a. Signal
    b. Wait
    c. SignalAndWait
    d. RemoveParticipant
    e. JoinParticipant
A

c. SignalAndWait

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. What code is equivalent with lock(syncObject){…}?
    a. Monitor.Lock(syncObject) {…}
    b. Monitor.TryEnter(syncObject) {…}
    c. Monitor.Enter(syncObject);
    try{…}
    finally{
    Monitor.Exit(syncObject);
    }
    d. Monitor.Lock(syncObject);
    try{…}
    catch{
    Monitor.Unlock(syncObject);
    }
A
c.	Monitor.Enter(syncObject);
   try{…}
 finally{
    Monitor.Exit(syncObject);
 }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. In a multithreaded application how would you increment a variable called counter in a lock free manner? Choose all that apply.
    a. lock(counter){
    counter++;
    }
    b. counter++;
    c. Interlocked.Add(ref counter, 1);
    d. Interlocked.Increment (counter);
    e. Interlocked.Increment (ref counter);
A

c. Interlocked.Add(ref counter, 1);

e. Interlocked.Increment (ref counter);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Which method will you use to signal and EventWaitHandle?
    a. Signal
    b. Wait
    c. Set
    d. Reset
    e. SignalAndWait
A

c. Set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly