Simple console application using Multi-threading Properties
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplicationSample
{
//class
MultiThereading
//{
public class ServerClass
{
// The
method that will be called when the thread is started.
public void InstanceMethod()
{
Console.Write("You are in
InstranceMethod.Running on Thread A");
Console.WriteLine("Thread A
Going to Sleep Zzzzzzzz");
// Pause
for a moment to provide a delay to make threads more apparent.
Thread.Sleep(3000);
Console.WriteLine("You are Back
in InstanceMethod.Running on Thread A");
}
public static void StaticMethod()
{
Console.WriteLine("You are in
StaticMethod. Running on Thread B.");
// Pause
for a moment to provide a delay to make threads more apparent.
Console.WriteLine("Thread B
Going to Sleep Zzzzzzzz");
Thread.Sleep(5000);
Console.WriteLine("You are back
in static method. Running on Thread B");
}
}
public class Simple
{
public static int Main(String[] args)
{
Console.WriteLine("Thread
Simple Sample");
ServerClass serverObject = new ServerClass();
//
Create the thread object, passing in the
//
serverObject.InstanceMethod method using a ThreadStart delegate.
Thread InstanceCaller = new
Thread(new ThreadStart(serverObject.InstanceMethod));
// Start
the thread.
InstanceCaller.Start();
Console.WriteLine("The Main()
thread calls this " +
"after
starting the new InstanceCaller thread.");
//
Create the thread object, passing in the
//
serverObject.StaticMethod method using a ThreadStart delegate.
Thread StaticCaller = new Thread(new
ThreadStart(ServerClass.StaticMethod));
// Start
the thread.
StaticCaller.Start();
Console.WriteLine("The Main ()
thread calls this " +
"after starting the new StaticCaller threads.");
Console.ReadKey();
return 0;
}
}
}
https://www.youtube.com/channel/UCKLRUr6U5OFeu7FLOpQ-FSw/videos
0 comments
Post a Comment