Write
a program for threading demonstration in Windows C#.NET
Nagpur University MCA V Semester, C#.Net, Embedded System Programming, Nagpur University Practical MCA V SEM
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace Practical3_ThredingDemo
{
class MyThread
{
public int i;
string thName;
public MyThread(string name)
{
i = 0;
thName = name;
}
public void run()
{
Console.WriteLine( "START : "+thName);
do
{
if (i % 2 != 0)
{
Thread.Sleep(400);
Console.WriteLine(thName + " : " + i);
}
i++;
} while (i <= 10);
Console.WriteLine( "END : "+thName );
}
}
class MultiThread
{
static void Main(string[] args)
{
int i = 0;
Console.WriteLine("START : Main Thread");
MyThread mt = new MyThread("Child Thread");
Thread newThread = new Thread(new ThreadStart(mt.run));
newThread.Start();
do
{
if(i%2==0)
Console.WriteLine("Main Thread : " + i);
Thread.Sleep(250);
i++;
} while ( i<= 10);
Console.WriteLine("END : Main Thread");
Console.ReadKey(true);
}
}
}
Write a program for threading demonstration in Windows C#.NET
Nagpur University MCA V Semester, C#.Net, Embedded System Programming, Nagpur University Practical MCA V SEM
OUTPUT
Write a program for threading demonstration in Windows C#.NET
Nagpur University MCA V Semester, C#.Net, Embedded System Programming, Nagpur University Practical MCA V SEM
Nagpur University MCA V Semester, C#.Net, Embedded System Programming, Nagpur University Practical MCA V SEM
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace Practical3_ThredingDemo
{
class MyThread
{
public int i;
string thName;
public MyThread(string name)
{
i = 0;
thName = name;
}
public void run()
{
Console.WriteLine( "START : "+thName);
do
{
if (i % 2 != 0)
{
Thread.Sleep(400);
Console.WriteLine(thName + " : " + i);
}
i++;
} while (i <= 10);
Console.WriteLine( "END : "+thName );
}
}
class MultiThread
{
static void Main(string[] args)
{
int i = 0;
Console.WriteLine("START : Main Thread");
MyThread mt = new MyThread("Child Thread");
Thread newThread = new Thread(new ThreadStart(mt.run));
newThread.Start();
do
{
if(i%2==0)
Console.WriteLine("Main Thread : " + i);
Thread.Sleep(250);
i++;
} while ( i<= 10);
Console.WriteLine("END : Main Thread");
Console.ReadKey(true);
}
}
}
Write a program for threading demonstration in Windows C#.NET
Nagpur University MCA V Semester, C#.Net, Embedded System Programming, Nagpur University Practical MCA V SEM
OUTPUT
OUTPUT
START : Main Thread
Main
Thread : 0
START : Child Thread
Child Thread : 1
Main
Thread : 2
Child Thread : 3
Main
Thread : 4
Child Thread : 5
Main
Thread : 6
Child Thread : 7
Main
Thread : 8
Child Thread : 9
END : Child Thread
Main
Thread : 10
END : Main Thread
Write a program for threading demonstration in Windows C#.NET
Nagpur University MCA V Semester, C#.Net, Embedded System Programming, Nagpur University Practical MCA V SEM
No comments:
Post a Comment