Can u create multiple threads of execution ?



Can u create multiple threads of execution ?..

Answer / tina

using System;
using System.Threading;

class MyThread {
public int count;
public Thread thrd;

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

// Entry point of thread.
void run() {
Console.WriteLine(thrd.Name + " starting.");

do {
Thread.Sleep(500);
Console.WriteLine("In " + thrd.Name +
", count is " + count);
count++;
} while(count < 10);

Console.WriteLine(thrd.Name + " terminating.");
}
}

public class MoreThreads {
public static void Main() {
Console.WriteLine("Main thread starting.");

// Construct three threads.
MyThread mt1 = new MyThread("Child #1");
MyThread mt2 = new MyThread("Child #2");
MyThread mt3 = new MyThread("Child #3");

do {
Console.Write(".");
Thread.Sleep(100);
} while (mt1.count < 10 ||
mt2.count < 10 ||
mt3.count < 10);

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

Is This Answer Correct ?    4 Yes 1 No

Post New Answer

More C Sharp Interview Questions

What is the Difference between read only and constant variables?

14 Answers   SilverKey,


If you want to write your own dot net language, what steps you will u take care?

0 Answers  


What’s the difference between System.String and System.Text.StringBuilder classes with example

2 Answers  


How do you mark a method obsolete?

0 Answers  


What are lambda expressions used for?

1 Answers  






What is the difference between “constant” and “readonly” variables in c#?

0 Answers  


WHAT ARE Design Patterns USING IN DOTNET

3 Answers   HP,


What is the difference between dispose() and finalize() methods in c#?

0 Answers  


What is the difference between string keyword and system.string class?

0 Answers  


Explain ACID rule of thumb for transactions.

1 Answers  


i have a table named login in mysql database containing (empid,fname,lname,mobno,emailid,usrname,usrpwd) i have 2 textboxes in which i enter my username and pwd..so based on what is entered in those textboxes it should retreive all other details of dat username in the remaining 6 textboxes..i want the code for this...

1 Answers   Royal Enfield,


Which layer executed first among these Application layer,Buisness layer or Data Base Layer?

2 Answers   L&T,


Categories