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 |
To allow an element to be accessed using a unique key which .NET collection class is used ?
How long does it take to learn c# for unity?
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?
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?
What?s the C# equivalent of C++ catch (?), which was a catch-all statement for any possible exception?
What is sorted list in c#?
What is a .exe extension files? How is it similar to .dll extension files?
Explain the difference between “system.array.clone()” and “system.array.copyto()” in c#?
What?s the difference between the System.Array.CopyTo() and System.Array.Clone()?
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?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)