Пример #1
0
        static void ThreadWorker(ref DataMonitor dataMonitor, char letter = 'A')
        {
            bool response;

            while ((response = dataMonitor.AddLetter(letter)))
            {
            }
        }
Пример #2
0
 static void PrintValue(DataMonitor zodis)
 {
     if (!threadsJoined)
     {
         Console.WriteLine(zodis.ToString());
         Task.Delay(0).ContinueWith((task) =>
         {
             PrintValue(zodis);
         });
     }
 }
Пример #3
0
        static void Main(string[] args)
        {
            DataMonitor   zodis   = new DataMonitor();
            List <Thread> threads = new List <Thread>();

            char[] raides = new char[] { 'A', 'B', 'C' };


            for (int i = 0; i < 3; i++)
            {
                int index = i;
                threads.Add(new Thread(() => ThreadWorker(ref zodis, raides[index])));
            }


            Task.Run(() =>
            {
                while (!threadsJoined)
                {
                    Console.WriteLine(zodis);
                }
            });

            threads.ForEach(thread =>
            {
                thread.Start();
            });

            threads.ForEach(thread =>
            {
                thread.Join();
            });

            threadsJoined = true;

            Console.WriteLine("Galutinis zodis: " + zodis);
        }