

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Join, Sleep and Abort methods in C# Threading
Join
Blocks the calling thread until a thread terminates, while continuing to perform standard COM and SendMessage pumping. This method has different overloaded forms.
Sleep
Makes the thread pause for a period of time.
Abort
The Abort method is used to destroy threads.
Let us see an example of Join() in threading −
Example
using System; using System.Diagnostics; using System.Threading; namespace Sample { class Demo { static void Run() { for (int i = 0; i < 2; i++) Console.Write("Sample text!"); } static void Main(string[] args) { Thread t = new Thread(Run); t.Start(); t.Join(); Console.WriteLine("Thread terminated!"); Console.Read(); } } }
Let us see an example of abort() and sleep() in Threading.
Example
using System; using System.Threading; namespace Demo { class ThreadCreationProgram { public static void CallToChildThread() { try { Console.WriteLine("Child thread starts"); // do some work, like counting to 10 for (int counter = 0; counter <= 10; counter++) { Thread.Sleep(500); Console.WriteLine(counter); } Console.WriteLine("Child Thread Completed"); } catch (ThreadAbortException e) { Console.WriteLine("Thread Abort Exception"); } finally { Console.WriteLine("Couldn't catch the Thread Exception"); } } static void Main(string[] args) { ThreadStart childref = new ThreadStart(CallToChildThread); Console.WriteLine("In Main: Creating the Child thread"); Thread childThread = new Thread(childref); childThread.Start(); //stop the main thread for some time Thread.Sleep(2000); //now abort the child Console.WriteLine("In Main: Aborting the Child thread"); childThread.Abort(); Console.ReadKey(); } } }
- Related Questions & Answers
- Abort in C#
- exit(), abort() and assert() in C/C++
- Differences between wait() and join() methods in Java
- Implicit Threading and Language-based threads
- Linear search using Multi-threading in C
- Multi-Threading Models
- How to perform a left outer join using linq extension methods in C#?
- What are threading issues?
- Difference between Wait and Sleep in Java
- Difference Between Inner Join and Outer Join in SQL
- C# Join() Method
- Accessing Attributes and Methods in C#
- Private and final methods in C#
- Python and multi-threading. Is it a good idea?
- Differences between wait() and sleep() method in Java?
Advertisements