.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Threading >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Threading in C# - Make it easy with Code

Posted By:Gaurav Arora       Posted Date: April 27, 2009    Points: 10    Category: Threading    URL: http://www.dotnetspark.com  
 

The following code-snippet gives a keen look on the simplest part of Thread in C# :

using System;

using System.Threading;

namespace CSharp.AStepAhead.threading

{

class threading

{

public threading()

{

//Thread th = new Thread(new ThreadStart(writeData("Gaurav")));

//th.Start();

}

public static string nm;

public static int i;

protected static void writeData()

{

//string str;

for (i = 0; i <= nm.Length - 1; i++)

{

Console.ForegroundColor = ConsoleColor.Blue;

Thread.Sleep(1000);

Console.WriteLine(" {0}", nm.Substring(i, 1));

//Console.WriteLine(str);

}

}

static void Main()

{

string name, lname;

Console.Write("Enter First Name : ");

name = Console.ReadLine();

Console.Write("Enter Last Name : ");

lname = Console.ReadLine();

threading.nm = lname;

Console.Clear();

Thread th = new Thread(new ThreadStart(writeData));

th.Start();

for (int j = 0; j <= name.Length - 1; j++)

{

Console.ForegroundColor = ConsoleColor.Green;

Console.Write(" {0}", name.Substring(j, 1));

Thread.Sleep(1000);

}

Console.ReadLine();

return;

}

}

}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend