Popular Localities

Bangalore

Delhi

Noida

Gurgaon

Mumbai

Hyderabad

Kolkata

Chennai

Pune

Ahmedabad

Chandigarh

Online Services

Student Enquiries

Jobs

loading......

coming soon

Coming Soon

We are in process of building the inventory of good professionals in this category

Got it!
C Sharp

C Sharp

+ Follow 3,273 Followers

Share

C Sharp Lessons

Extension Methods in C#
Extension methods enables you to add methods to existing types without creating a new derived type, recompiling or otherwise modifying the original type. Extension methods are special type of static...

Reni Varghese | 05 Nov

0 0
0

Trending Discussions

S

What is a best book to learn c # language & asp.net

2 4

Show previous answers

Manoj Kumar Vishwakarma | 09 Apr

perfect introduction to C# By PwPrins

Naveen Nn | 09 Apr

Apress C# For Beginners

S

Show previous answers

Rakesh G | 12 Mar

if you are beginner you can start with HeadFirst Labs books, they are good. Manning Publications books are excellent for intermediate level. But personally i recommend MSDN articles for authentic and more information. Each and every topic is will be explained very well.

Rakesh G | 12 Mar

I can provide you the best training and learning experience. If you are interested let me know.

M

Show previous answers

Dinesh Joshi | 13/12/2015

Use System.Threading for Create threads.

Chandrashekar Achary | 14 Jan

This example demonstrates how to create and start a thread, and shows the interaction between two threads running simultaneously within the same process. Note that you don't have to stop or free the thread. This is done automatically by the .NET Framework common language runtime. The program begins by creating an object of type Alpha (oAlpha) and a thread (oThread) that references the Beta method of the Alpha class. The thread is then started. The IsAlive property of the thread allows the program to wait until the thread is initialized (created, allocated, and so on). The main thread is accessed through Thread, and the Sleep method tells the thread to give up its time slice and stop executing for a certain amount of milliseconds. The oThread is then stopped and joined. Joining a thread makes the main thread wait for it to die or for a specified time to expire (for more details, see Thread.Join Method). Finally, the program attempts to restart oThread, but fails because a thread cannot be restarted after it is stopped (aborted). For information on temporary cessation of execution, see Suspending Thread Execution. public class Alpha { // This method that will be called when the thread is started public void Beta() { while (true) { Console.WriteLine("Alpha.Beta is running in its own thread."); } } }; public class Simple { public static int Main() { Console.WriteLine("Thread Start/Stop/Join Sample"); Alpha oAlpha = new Alpha(); // Create the thread object, passing in the Alpha.Beta method // via a ThreadStart delegate. This does not start the thread. Thread oThread = new Thread(new ThreadStart(oAlpha.Beta)); // Start the thread oThread.Start(); // Spin for a while waiting for the started thread to become // alive: while (!oThread.IsAlive); // Put the Main thread to sleep for 1 millisecond to allow oThread // to do some work: Thread.Sleep(1); // Request that oThread be stopped oThread.Abort(); // Wait until oThread finishes. Join also has overloads // that take a millisecond interval or a TimeSpan object. oThread.Join(); Console.WriteLine(); Console.WriteLine("Alpha.Beta has finished"); try { Console.WriteLine("Try to restart the Alpha.Beta thread"); oThread.Start(); } catch (ThreadStateException) { Console.Write("ThreadStateException trying to restart Alpha.Beta. "); Console.WriteLine("Expected since aborted threads cannot be restarted."); } return 0; } } Example Output Thread Start/Stop/Join Sample Alpha.Beta is running in its own thread. Alpha.Beta is running in its own thread. Alpha.Beta is running in its own thread. ... ... Alpha.Beta has finished Try to restart the Alpha.Beta thread ThreadStateException trying to restart Alpha.Beta. Expected since aborted threads cannot be restarted.

Thousands of experts Tutors, Trainers & other Professionals are available to answer your questions

Ask a Pro

Recommended for you

About UrbanPro

UrbanPro.com helps you to connect with the best C Sharp Classes in India. Post Your Requirement today and get connected.

Have a Question?

Thousands of expert tutors are available to answer your question

Looking for C Sharp Classes?

Find best C Sharp Classes in your locality on UrbanPro.

FIND NOW

Do you offer C Sharp Classes?

Create Free Profile Now »

Top Contributors

Manoj Kumar

2 Answers

Rakesh

2 Answers

Naveen

1 Answer

Shashanka

1 Answer

Dinesh

1 Answer

Sandhya

1 Answer

Chandrashekar

1 Answer

Ashok

1 Answer

Samiksha

1 Answer

Sponsored

Find Best C Sharp Classes?

Find Now »