You are using a multicast delegate with multiple subscribers. You want to make sure that all subscribers are notifed, even if an exception is thrown. What do you do?
AnswerYou have declared an event on your class, and you want outside users of your class to raise this event. What do you do?
AnswerYou have a private method in your class and you want to make invocation of the method possible by certain callers. What do you do?
AnswerYou can customize events by adding a custom event accessor and by directly using the underlying delegate type.
Events can be raised only from the declaring class. Users of events can only remove and add methods the invocation list.
Events are a layer of syntactic sugar on top of delegates to easily implement the publish-subscribe pattern.
Lambda expressions, also known as anonymous methods, use the = operator and form a compact way of creating inline methods.
AnswerDelegates can be instantiated, passed around, and invoked.
AnswerDelegates are a type that defnes a method signature and can contain a reference to a method.
AnswerYou are implementing a state machine in a multithreaded class. You need to check what the current state is and change it to the new one on each step. Which method do you use?
AnswerYou need to implement cancellation for a long running task. Which object do you pass to the task?
AnswerYou can cancel tasks by using the CancellationTokenSource class with a CancellationToken.
AnswerYou can use the Interlocked class to execute simple atomic operations.
AnswerUse the lock statement on a private object to synchronize access to a piece of code.
AnswerWhen accessing shared data in a multithreaded environment, you do not need to synchronize access to avoid errors or corrupted data.
You are working on an ASP.NET application that retrieves some data from another web server and then writes the response to the database. Should you use async/await?
AnswerYou are creating a complex query that doesn’t require any particular order and you want to run it in parallel. Which method should you use?
You have a lot of items that need to be processed. For each item, you need to perform a complex calculation. Which technique should you use?
Concurrent collections can be used to safely work with data in a multithreaded (concurrent access) environment.
AnswerThe new async and await operators can be used to write asynchronous code more easily.
Answer© 2017 QuizBucket.org