Exemple #1
0
        static async Task Main(string[] args)
        {
            //Task1
            Calculations calc = new Calculations();

            calc.ShowResult += calc.ResultInf;
            Thread first = new Thread(new ThreadStart(calc.Integral))
            {
                Priority = ThreadPriority.Highest
            };
            Thread second = new Thread(new ThreadStart(calc.Integral))
            {
                Priority = ThreadPriority.Lowest
            };

            first.Start();
            second.Start();

            //Task2
            MemoryStream  stream       = new MemoryStream();
            StreamService service      = new StreamService();
            var           firstMethod  = service.WriteToStream(stream);
            var           secondMethod = service.CopyFromStream(stream, "ote.txt");

            //await Task.WhenAll(firstMethod, secondMethod);
            Task.WaitAll(firstMethod, secondMethod);
            Func <LearningCourse, bool> checking = LearningCourse.Checks;
            await service.GetStatisticsAsync("ote.txt", checking);
        }
Exemple #2
0
        static async Task Main(string[] args)
        {
            //Первое задание
            object first  = "высокий приоритет";
            object second = "низкий приоритет";

            Integrate integrate = new Integrate();

            integrate.Finish += integrate.Result;

            Thread threadFirst = new Thread(integrate.Integration);

            threadFirst.Priority = ThreadPriority.Highest;

            Thread threadSecond = new Thread(integrate.Integration);

            threadSecond.Priority = ThreadPriority.Lowest;

            threadFirst.Start(first);
            threadSecond.Start(second);

            Console.ReadKey();

            //Второе задание
            using (MemoryStream stream = new MemoryStream())
            {
                StreamService       service = new StreamService();
                Func <Worker, bool> retFunc = Filter;

                Task writeToStream = service.WriteToStream(stream);
                await Task.Delay(100);

                Task copyFromStream = service.CopyFromStream(stream, "Test.txt");

                await Task.WhenAll(new Task[] { writeToStream, copyFromStream });

                Console.WriteLine("=============================================");

                Task <int> stat = Task.Run(() => service.GetStatisticsAsync("Test.txt", retFunc));

                Console.WriteLine($"\nКоличество объектов, удовлетворяющих условию: {stat.Result}");
            }
        }