Multithreading Questions with Answers

8 practice questions on Multithreading (C#) with answers and step-by-step solutions. Try 8 samples below, then practise all 8 free in the AptiNest app.

Sample questions

Question 1Medium

What is Thread?

  1. Its a feature of modern operating system with which we can run multiple programs at same time example world, excel etc.
  2. A thread is the basic unit to which the operating system allocates processor time.
  3. Its a Caching mechanism.
  4. All the above.

Answer: B. A thread is the basic unit to which the operating system allocates processor time.

Explanation

A thread is defined as the execution path of a program. Each thread defines a unique flow of control. If your application involves complicated and time consuming operations then it is often helpful to set different execution paths or threads, with each thread performing a particular job.
Threads are lightweight processes. One common example of use of thread is implementation of concurrent programming by modern operating systems. Use of threads saves wastage of CPU cycle and increaseefficiency of an application.

Step-by-step solution

  1. A thread is the execution path, or flow of control, inside a program.
  2. The operating system schedules threads and gives each one processor time.
  3. Option A describes running several programs at once, which is multitasking, not a thread.
  4. So the answer is option B, the basic unit to which the OS allocates processor time.

Why the other options are wrong

  • A. Running several programs at once is multitasking; a thread is one flow inside a program.
  • C. Caching is a different mechanism, not a thread.
  • D. Options A and C are wrong, so 'all the above' is wrong.

Tip: A process is a running program; a thread is a path of execution inside a process.

Question 2Medium

How to pause or sleep a thread in c#.net?

  1. Thread.Sleep(1000)
  2. Thread.Pause(1000)
  3. Thread.Stop(1000)
  4. Thread.Wait(1000)

Answer: A. Thread.Sleep(1000)

Explanation

Thread.Sleep(1000) pauses the current thread for 1000 milliseconds. The other options are not methods that pause a thread.

Step-by-step solution

  1. The C# Thread class has a static Sleep method that takes milliseconds.
  2. Thread.Sleep(1000) pauses the current thread for one second.
  3. So option A is correct.

Why the other options are wrong

  • B. Thread has no Pause method.
  • C. Thread has no Stop method that takes a time.
  • D. Thread has no static Wait method with this form.

Tip: Use Thread.Sleep(milliseconds) to pause a thread.

Question 3Medium

When working with shared data in threading how do you implement synchronization?

  1. Using Locks
  2. Using Joins
  3. Using Multiple threads
  4. None of the above

Answer: A. Using Locks

Explanation

To synchronize access to shared data in threading, locks are used to ensure that only one thread can modify the data at a time, preventing conflicts and maintaining data integrity.

Step-by-step solution

  1. Threads that share data can overwrite each other's changes.
  2. A lock lets only one thread enter the protected code at a time.
  3. So locks synchronize access to shared data.
  4. Option A, Using Locks, is the correct answer.

Why the other options are wrong

  • B. Join makes one thread wait for another to finish; it does not guard shared data.
  • C. Creating more threads adds the problem; it is not a way to synchronize.
  • D. Locks are a valid answer, so none of the above is wrong.

Tip: Locks, mutexes or monitors protect shared data; join only waits for a thread to end.

Question 4Medium

Which namespaces has threading?

  1. System.Thread
  2. Systems.Threading
  3. Systems.Threads
  4. Systems.ThreadDomain

Answer: B. Systems.Threading

Explanation

System.Threading is the namespace with the classes for creating and managing threads. A program that uses threads must import it with using System.Threading;. System.Thread is not a namespace, and the other options are misspelled or made-up names.

Step-by-step solution

  1. The threading classes live in the System.Threading namespace.
  2. Option B is that name with a typo, Systems.Threading, so it is the intended answer.
  3. System.Thread, Systems.Threads and Systems.ThreadDomain are not the threading namespace.
  4. So the correct answer 1 is correct.

Why the other options are wrong

  • A. System.Thread is missing the s and names a class, not the namespace.
  • C. Systems.Threads has the wrong ending; the namespace is System.Threading.
  • D. Systems.ThreadDomain is not a threading namespace.

Tip: Threading types are in System.Threading; check the exact namespace spelling.

Question 5Medium

Which of the following is true about AppDomain?
I. An AppDomain basically provides an isolated region in which code runs inside of a process.
II. An easy way to think of it is almost like a lighter weight process sitting inside of your main process. Each AppDomain exists within a process in complete isolation, which allows you to run code safely ,with separate security,etc.

  1. I
  2. II
  3. I and II
  4. None of the above

Answer: C. I and II

Explanation

Operating systems and runtime environments typically provide some form of isolation between applications. For example, Windows uses processes to isolate applications. This isolation is necessary to ensure that code running in one application cannot adversely affect other, unrelated applications. Application domains provide an isolation boundary for security, reliability, and versioning, and for unloading assemblies.
Application domains are typically created by runtime hosts, which are responsible for bootstrapping the common language runtime before an application is run.

Step-by-step solution

  1. AppDomain isolates code within a process.
  2. It acts like a lightweight process inside the main process.
  3. Each AppDomain has its own security and isolation settings.
  4. Both statements I and II correctly describe AppDomain.
  5. Final answer: I and II.

Why the other options are wrong

  • A. Statement II is also true about AppDomain.
  • B. Statement I is also true about AppDomain.
  • D. Both statements I and II are true about AppDomain.

Question 6Medium

Is the following true about Thread.join() in threading?

- I. The Thraed.join method is useful for determining if a thread has completed before starting another task
- II. The join method waits a specified amount of a thread to ends before the time-out,join returns true ;otherwise it returns false.
- III. once you call join,the calling procedure stops and waits for the thread to signal that it is done.

  1. Yes
  2. No

Answer: A. Yes

Explanation

Yes, all three statements are true. Thread.Join makes the calling code wait until that thread finishes. With a timeout, Join returns true if the thread finished in time and false if the time ran out.

Step-by-step solution

  1. Join makes the calling thread wait until the other thread has finished.
  2. The timed version of Join returns true if the thread finished and false if it timed out.
  3. All three statements are true.
  4. So the correct answer, Yes, is correct.

Why the other options are wrong

  • B. All three statements are true, so No is wrong.

Tip: Join blocks the caller until the thread ends or the timeout passes.

Question 7Medium

Can we have multiple threads in one App domain?

  1. Yes
  2. No

Answer: A. Yes

Explanation

One or more threads run in an AppDomain is a runtime representation of logical process within a physical process. Each AppDomain is started with a single thread ,but can create additional threads from any of its threads.

Step-by-step solution

  1. AppDomain starts with one thread.
  2. Threads can be created inside an AppDomain from existing threads.
  3. Multiple threads can run in one AppDomain.
  4. So, the answer is Yes.

Why the other options are wrong

  • B. AppDomain can have multiple threads, so 'No' is incorrect.

Tip: Remember: AppDomain supports multiple threads for parallel execution.

Question 8Medium

Can we change the thread priority in c#.net?

  1. Yes
  2. No

Answer: A. Yes

Explanation

Yes. A thread's Priority property can be set, for example thread2.Priority = ThreadPriority.Highest;. Priority only changes the scheduling preference, so it does not guarantee the order in which the threads print.

Step-by-step solution

  1. In C#, a thread's Priority property can be set, for example thread2.Priority = ThreadPriority.Highest.
  2. The levels are Highest, AboveNormal, Normal, BelowNormal and Lowest.
  3. So the answer to 'can we change thread priority' is Yes: option A.

Why the other options are wrong

  • B. Priority is a settable property, so 'No' is wrong.

Tip: Thread priority is a hint to the scheduler; it does not guarantee the order of output.

Practise all 8 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all C# topics · All topics