using System;
using System.IO;
using System.Threading;
//вариант 2
public class AutoResetEventSample
{
public static AutoResetEvent evWriter;
public static AutoResetEvent evReader;
public static AutoResetEvent evVowels;
public static AutoResetEvent evConsonants;
public static string str = "";
public static string path = @"C:\Users\dvdvd\Desktop\лаб6 ОС\test.txt";
public static bool reading = true;
public static string mass = "";
public static string f = "";
public static void Писатель()
{
char[] b;
while (reading)
{
//evWriter.WaitOne();
mass = f;
f = null;
if (mass != null)
{
b = mass.ToCharArray();
foreach (char i in b)
{
f += char.ToLower(i);
}
Console.WriteLine(f);
f = null;
str = null;
}
//evReader.Set();
}
}
public static void Гласные()
{
char[] x;
while (reading)
{
evWriter.WaitOne();
mass = f;
f = null;
if (mass != null)
{
x = mass.ToCharArray();
foreach (char i in x)
{
var message = x;//сюда нажно вроде как поставить переменную в которой нужный текст
for (int k = 0; k < message.Length; k++)
{
if ("aeiouAEIOU".IndexOf(message[k]) >= 0)
Console.Write(message[k]);
}
}
Console.WriteLine(f);
f = null;
str = null;
}
evReader.Set();
}
}
public static void Согласные()
{
char[] x;
while (reading)
{
evWriter.WaitOne();
mass = f;
f = null;
if (mass != null)
{
x = mass.ToCharArray();
foreach (char i in x)
{
var message = x;
for (int z = 0; z < message.Length; z++)
{
if ("qwrtpsdfghjklzxcvbnmQWRTPSDFGHJKLZXCVBNM".IndexOf(message[z]) >= 0)
Console.Write(message[z]);
}
}
f = null;
str = null;
}
evReader.Set();
}
}
public static void Читатель()
{
reading = true;
StreamReader sr = new StreamReader(path);
while (!sr.EndOfStream)
{
while ((str = sr.ReadLine()) != null)
{
f = str;
}
evReader.WaitOne();
if (str == null)
Console.WriteLine(f);
str = sr.ReadLine();
evWriter.Set();
}
reading = false;
sr.Close();
}
public static void Main()
{
evWriter = new AutoResetEvent(true);
evReader = new AutoResetEvent(false);
evVowels = new AutoResetEvent(false);
evConsonants = new AutoResetEvent(false);
Thread читатель = new Thread(Читатель);
Thread писатель = new Thread(Писатель);
Thread гласные = new Thread(Гласные);
Thread согласные = new Thread(Согласные);
читатель.Start();
писатель.Start();
гласные.Start();
согласные.Start();
evReader.Set();
читатель.Join();
писатель.Join();
гласные.Join();
согласные.Join();
Console.ReadKey();
}
}