Home   Cover Cover Cover Cover
 

Ein-/Ausgabe-Threads

A01.cs
using System;
using System.Threading;

class ThreadSample {
  static char ch = '*';
  
  static void Print() {
    for (;;) {
      Console.Write(ch);
      Thread.Sleep(10);
    }
  }
  
  static void Read() {
    for (;;) {
      string s = Console.ReadLine();
      if (s.Length > 0) ch = s[0];
    }
  }
  
  static void Main() {
    Thread printer = new Thread(new ThreadStart(Print));
    Thread reader = new Thread(new ThreadStart(Read));
    printer.Start();
    reader.Start();
    Console.WriteLine("Terminate the program with Ctrl-C");
  }

}