Exemplo n.º 1
0
        private static void OnCompleted(object sender, CompletedEventArgs args)
        {
            var elapsedTime = stopWatch.Elapsed;

            stopWatch.Stop();

            switch (args.Status)
            {
            case CompletionStatus.Successed:
                Console.WriteLine("Operation completed successfully.");
                Console.WriteLine(string.Format("Time spent: {0}.", elapsedTime));
                Console.WriteLine(string.Format("Input file size: {0} bytes.", args.InputFileSize));
                Console.WriteLine(string.Format("Output file size: {0} bytes.", args.OutputFileSize));
                programResult = 0;
                break;

            case CompletionStatus.Cancelled:
                Console.WriteLine("Operation has been canceled.");
                programResult = 1;
                break;

            case CompletionStatus.Faulted:
                Console.WriteLine("Operation failed.");
                foreach (var exception in args.Exceptions)
                {
                    Console.WriteLine(exception.Message);
                }
                programResult = 1;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            autoResetEvent.Set();
        }