How to Create Timer
of Multithread based Program on console Application in C#
Hi
Friends,
This Article I have creates Timer using multi-thread on console Application.
Following
given steps:
First
need u have installed visual studio 2010
Then u open vs and select new projects
After open new projects u see this window and follow steps…
After
all vs open on program platform u write ur C# coding on console based…
you
visit vs programming platform and write here coding or program developed
console based application...
Example:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace Clock_MultiThreading
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to Timer Clock Multithread Program\t By
Krishna Singh");
Console.SetCursorPosition(03, 08); //set the cursor
position
Console.Write("12
hour clock in "); //set clock type 12hrs or 24hrs i set here 12 hrs clock
Console.SetCursorPosition(20, 08);
Console.WriteLine("hr:min:sec:M.Sec");
Console.Beep();
for (int hr = 0; hr
<= 11; hr++) //
Apply for loop for hour
{
for (int
min = 0; min <= 59; min++) // Apply for loop
for min
{
for (int
sec = 0; sec <= 59; sec++) // Apply for loop
for sec
{
for (int Msec = 0; Msec < 99;
Msec++) //
Apply for loop for Msec
{
if (hr < 10) //Apply if
condition for hour
{
if (min < 10)
//Apply if condition for min
{
if (sec < 10)
//Apply if condition for sec
{
Console.SetCursorPosition(18, 10);
Console.Write("[
0{0}: 0{1}: 0{2}:{3} ]", hr, min, sec, Msec);
Thread.Sleep(10); //apply
thread with time sleep
}
else if (sec >=
10)
{
Console.SetCursorPosition(18, 10);
Console.Write("[
0{0}: 0{1}: {2}:{3} ]", hr, min, sec, Msec);
Thread.Sleep(10);
//apply thread with time sleep
}
}
else if (min >=
10)
{
if (sec < 10)
{
Console.SetCursorPosition(18, 10);
Console.Write("[
0{0}: {1}: 0{2}:{3} ]", hr, min, sec, Msec);
Thread.Sleep(10);
//apply thread with time slep
}
else if (sec >=
10)
{
Console.SetCursorPosition(18, 10);
Console.Write("[
0{0}: {1}: {2}:{3} ]", hr, min, sec, Msec);
Thread.Sleep(10);
//apply thread with time sleep
}
}
}
else if (hr >= 10)
{
if (min < 10)
{
if (sec < 10)
{
Console.SetCursorPosition(20, 10);
Console.Write("{0}:0{1}:0{2}:{3}",
hr, min, sec, Msec);
Thread.Sleep(10); //apply thread with
time sleep
}
else if (sec >=
10)
{
Console.SetCursorPosition(20, 10);
Console.Write("{0}:0{1}:{2}:{3}",
hr, min, sec, Msec);
Thread.Sleep(10);
//apply thread with time sleep
}
}
else if (min >=
10)
{
if (sec < 10)
{
Console.SetCursorPosition(20, 10);
Console.Write("{0}:{1}:0{2}:{3}",
hr, min, sec, Msec);
Thread.Sleep(10);
//apply thread with time sleep
}
else if (sec >=
10)
{
Console.SetCursorPosition(20, 10);
Console.Write("{0}:{1}:{2}:{3}",
hr, min, sec, Msec);
Thread.Sleep(10); //apply thread with
time sleep
}
}
}
}
Console.Beep();
}
Console.Beep();
Console.Beep();
}
}
Console.ReadKey();
}
}
}
Output below here …
SO Friends these are few
Blogs that will help you in " How to Create Timer of Multithread based Program on console
Application in C#" next
time i will put some more interesting Blogs thank you..I Hope Helpfull u..
enjoy :).Krishna Singh