Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


give an example for suspending, resuming, and stopping a
thread ?



give an example for suspending, resuming, and stopping a thread ?..

Answer / tina

using System;
using System.Threading;

class MyThread {
public Thread thrd;

public MyThread(string name) {
thrd = new Thread(new ThreadStart(this.run));
thrd.Name = name;
thrd.Start();
}

// This is the entry point for thread.
void run() {
Console.WriteLine(thrd.Name + " starting.");

for(int i = 1; i <= 1000; i++) {
Console.Write(i + " ");
if((i%10)==0) {
Console.WriteLine();
Thread.Sleep(250);
}
}
Console.WriteLine(thrd.Name + " exiting.");
}
}

public class SuspendResumeStop {
public static void Main() {
MyThread mt1 = new MyThread("My Thread");

Thread.Sleep(1000); // let child thread start executing

mt1.thrd.Suspend();
Console.WriteLine("Suspending thread.");
Thread.Sleep(1000);

mt1.thrd.Resume();
Console.WriteLine("Resuming thread.");
Thread.Sleep(1000);

mt1.thrd.Suspend();
Console.WriteLine("Suspending thread.");
Thread.Sleep(1000);

mt1.thrd.Resume();
Console.WriteLine("Resuming thread.");
Thread.Sleep(1000);

Console.WriteLine("Stopping thread.");
mt1.thrd.Abort();

mt1.thrd.Join(); // wait for thread to terminate

Console.WriteLine("Main thread terminating.");
}
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

To allow an element to be accessed using a unique key which .NET collection class is used ?

0 Answers   Siebel,


How long does it take to learn c# for unity?

0 Answers  


How you will connect to windows directory in c#?

2 Answers   HP, nTech Solutions,


What is gac? What are the steps to create an assembly and add it to the gac?

0 Answers  


I was trying to use an out int parameter in one of my functions. How should I declare the variable that I am passing to it?

0 Answers  


What?s the C# equivalent of C++ catch (?), which was a catch-all statement for any possible exception?

1 Answers  


What is sorted list in c#?

0 Answers  


What is a .exe extension files? How is it similar to .dll extension files?

0 Answers   Accenture,


Explain the difference between “system.array.clone()” and “system.array.copyto()” in c#?

0 Answers  


What?s the difference between the System.Array.CopyTo() and System.Array.Clone()?

6 Answers   Wipro,


what is the difference between arraylist and hash table using a simple program?

3 Answers   CGI, Polaris, SunGard,


What C# keyword class access modifier specifies that the class is concrete and CANNOT be derived from?

3 Answers  


Categories