CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Threading in C# - A Simple Codesnippet
Submitted By Gaurav Arora
On 3/22/2009 7:11:53 AM
Tags: C#,CodeDigest  

Threading in C# - Easier to write

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;

}

}

}

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..