Write the sample code for threading in c# .net..

Answer Posted / alcheringa

using system.threading;
// this is the function that we want to invoke in a new
thread

static void doit()
{
for (int i=0 ; i < 10; i++)
{
console.writeline("doing somethin");
}
}
// this is the main fucntion

public static void main()
{
// threadstart is the delegate
// we need to pass the method, ts accept's method name as
the parameter
threadstart ts=new threadstart(doit);
// this is how we define a new thread

thread tr=new thread(ts);
// we invoke the thread
tr.start()
conosle.readline();
}

Is This Answer Correct ?    22 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can constructor have return type c#?

804


What do u mean by thread safe?

694


Is linkedhashset synchronized?

809


What is hashset c#?

677


Explain the different types of delegates used in c#.

713


What is difference between array and arraylist c#?

668


Write the difference between TypeOf and GetType?

775


What is a verbatim string literal and why do we use it?

692


What is protected internal modifier in C#?

760


Int map to which .net types?

749


What are methods in C#?

714


What is difference between array and arraylist in c#?

646


What are extension methods and where can we use them?

649


What is a thread c#?

667


What is querystring in c#?

693