マルチスレッド-C#


public class MyThread

// 

  {



  public double Diameter=10;



  public double Result=0;



  public MyThread(int Diameter)



  {



  this.Diameter = Diameter;



  }



  public void Calculate()



  {



  Console.WriteLine( "Calculate Start");



  Thread.Sleep(2000);



  Result = Diameter*Math.PI;;



  Console.WriteLine("Calculate End, Diameter is ,Result is " ,this.Diameter, Result);



  }



  }



  MyThread t=new MyThread(5.0);



  ThreadStart threadStart=new ThreadStart(t.Calculate)



  Thread thread=new Thread(threadStart);



  thread.Start();

}

// 

using System;  

using System.Collections.Generic;  

using System.Text;  

using System.Threading;  

namespace    

{  

    class Program  

    {  

        static void Main(string[] args)  

        {  

            Console.WriteLine(" , ");  

            Thread t = new Thread(new ThreadStart(ThreadProc));  

            t.Start();  

            for (int i = 0; i < 4; i++)  

            {  

                Console.WriteLine(" :" + i);  

                Thread.Sleep(1000);  

            }  

            Console.WriteLine(" Join ");  

            // ,Join , ,   

            t.Join();  

            Console.WriteLine(" ");  

        }  

        public static void ThreadProc()  

        {  

            for (int i = 0; i < 10; i++)  

            {  

                Console.WriteLine("ThreadPorc:{0}", i);  

                Thread.Sleep(1000);//   

            }  

  

  

        }  

    }  

}