C# .NET multithreading quiz

This topic covers threading common issues, best practices and how to implement multi-threading application correctly

This quiz is in C# .NET quiz collection.

Start quiz
  • 1.

    A thread can be seen as a virtualized CPU

  • 2.

    Using multiple threads can neither improve responsiveness, nor enable you to make use of multiple processors

  • 3.

    The Thread class can be used if you want to create your own threads explicitly. Otherwise, you can use the ThreadPool to queue work and let the runtime handle things.

  • 4.

    A Task object encapsulates a job that needs to be executed. Tasks are the recommended way to create multithreaded code.

  • 5.

    The Parallel class can not be used to run code in parallel.

  • 6.

    PLINQ is an extension to LINQ to run queries in parallel.

  • 7.

    The new async and await operators can be used to write asynchronous code more easily.

  • 8.

    Concurrent collections can be used to safely work with data in a multithreaded (concurrent access) environment.

  • 9.

    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?

  • 10.

    You 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?

  • 11.

    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?

  • 12.

    When accessing shared data in a multithreaded environment, you do not need to synchronize access to avoid errors or corrupted data.

  • 13.

    Use the lock statement on a private object to synchronize access to a piece of code.

  • 14.

    You can use the Interlocked class to execute simple atomic operations.

  • 15.

    You can cancel tasks by using the CancellationTokenSource class with a CancellationToken.

  • 16.

    You 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?

  • 17.

    You need to implement cancellation for a long running task. Which object do you pass to the task?

© 2017 QuizBucket.org