Threads Interview Questions and Answers Part 2

1. How to stop a long running thread?
Ans. Thread.Abort() will stop the thread execution.

2. How to know the current thread?
Ans. System.Threading.Thread.CurrentThread - to get the current thread instance.

3. How we can make the thread run in background?
Ans ThreadName.IsBackground = true; This will make Thread to run in background process.
 
4. Explain Daemon threads and how to created a Daemon?
Ans. This threads run in background and stop automatically when idle. 
     We can make any thread Daemon by setting,  "Thread.Isbackground=true"
Example: "Garbage collector"
 
5. What are threading priorities available?
Ans. Following are the threading priorities,            

ThreadPriority.Highest
ThreadPriority.AboveNormal
ThreadPriority.Normal
ThreadPriority.BelowNormal
ThreadPriority.Lowest

Example :  ThreadName.Priority = ThreadPriority.BelowNormal; 

6. Can we use events with threading?
Ans. Yes, we can use events with thread.

7. Why we use events with threadings?
Ans. To synchronize one thread with other.

8. What is Event Wait Handle in threading?
Ans. Event Wait Handle allows threads to communicate with each other by signaling and by waiting for signals.
     They use signals to release one or more waiting threads.

9. How to know the status of thread?
Ans. Thread status can be known by using ThreadName.ThreadState property.

10. What are the thread states available?
Ans. Following are the states,
ThreadState.Running
ThreadState.Aborted
ThreadState.AbortRequested
ThreadState.Stopped
ThreadState.StopRequested
ThreadState.Suspended
ThreadState.SuspendRequested
ThreadState.Background
ThreadState.Unstarted
ThreadState.WaitSleepJoin



Subscribe

Receive Quality Tutorials Straight in your Inbox by submitting your Email below:

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker