Chapter 12 - Improving Performance and Scalability with Multitasking

  1. By convention, what suffix should be applied to a method that returns a Task or a Task<T>?
    • Async, for example, OpenAsync for a method named Open.
  2. To use the await keyword inside a method, which keyword must be applied to the method declaration?
    • The async keyword must be applied to the method declaration.
  3. How do you create a child task?
    • Call the Task.Factory.StartNew method with the TaskCreationOptions.AttachToParent option to create a child task.
  4. Why should you avoid the lock keyword?
    • The lock keyword does not allow you to specify a timeout; this can cause deadlocks. Use Monitor.Enter with a TimeSpan and Monitor.Exit instead.
  5. When should you use the Interlocked class?
    • If you have integers ...

Get C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.