yyy

yyy


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

using System.IO;


namespace ConsoleApplication1

{

  class Program

  {

    public static int[] array = new int[20];

    public static int value1, value2;

    static void OneThread()

    {

      Random rnd = new Random();

      int i = 0;

      while (i < 100)

      {

        value1 = rnd.Next(0, 100);

        Console.WriteLine(i + ": " + value1);

        array[i % 20] = value1;

        i++;

        Thread.Sleep(500);

      }

    }

    static void TwoThread()

    {

      using (StreamWriter sw = new StreamWriter("S:\\Array.txt"))

      {

        for (int j = 0; j < 5; j++)

        {

          Thread.Sleep(10000);

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

          {

            sw.WriteLine(i + ": " + array[i]);

          }          

        }

      }

    }

    static void ThreeThread()

    {

    }

    static void Main(string[] args)

    {

      Thread thread1 = new Thread(new ThreadStart(OneThread));

      Thread thread2 = new Thread(new ThreadStart(TwoThread));

      Thread thread3 = new Thread(new ThreadStart(ThreeThread));

      thread1.Start();

      thread2.Start();

      Console.ReadLine();

    }

  }

}


Report Page