Beispiel #1
0
        static void Main(string[] args)
        {
            Stopwatch stopWatch = new Stopwatch();
            var       path      = @"FileForTests/BigFile.txt";
            var       readasync = new ParserFileMultithreaded();

            stopWatch.Start();
            var res = readasync.ReadAllFileAsync(path, 1024 * 10, tokenSource.Token).
                      ContinueWith(task =>
            {
                tokenSource.Cancel();
                return(task.Result);
            });

            var cancellationTask = Task.Run(() =>
            {
                Console.ReadKey(true);
                if (res.IsCompleted)
                {
                    return;
                }

                tokenSource.Cancel();
            }, tokenSource.Token);

            Console.WriteLine(res.Result);
            stopWatch.Stop();
            Console.WriteLine(stopWatch.ElapsedMilliseconds);
        }