using System;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.Remoting.Messaging;
namespace ConsoleProject
{
class MainClass
{
static int x = 100;
public static void Main(string[] args)
{
//2ͭͷεϨουͰڞ௨ͷϑΟʔϧυ(ࢿݯ)Λར༻͢Δ
Thread t1 = new Thread(new ThreadStart(ShowAndIncrement));
t1.Start();
Thread t2 = new Thread(new ThreadStart(Show));
t2.Start();
//ऴྃͪ
t1.Join();
t2.Join();
Console.WriteLine("exit...");
}
public static void ShowAndIncrement()
{
Thread.Sleep(100);
Console.WriteLine("ShowAndIncrement Method called. ref value = { 0}", x++);
}
public static void Show()
{
Console.WriteLine("Show Method called. ref value = { 0}", x);
}
}
}
ShowAndIncrement͕࣌ؒ
͔͔ΔॲཧͳͷͰɺ͜ΕͰ
ࢥ͏Α͏ͳॱ൪Ͱ࣮ߦ͞Εͳ͍
ThreadΓΛαϙʔτ͍ͯ͠ͳ͍ͷͰ
ϑΟʔϧυΛͬͯڞ༗͢Δ
ThreadStartҾ
αϙʔτ͞Εͯͳ͍