コード例 #1
0
        static void Main(string[] args)
        {
            var manager = new ProgressManager();

            manager.Add(new SimplyProgressive(100, (e, token) =>
            {
                var total = 100;
                var value = 0;
                var r     = new Random();
                while (value < 100)
                {
                    Thread.Sleep(r.Next(200, 800));
                    value += r.Next(1, 30);
                    e.Report(new ProgressValueChangedEventArgs(total, Math.Min(total, value), null));
                }
                e.Report(new ProgressValueChangedEventArgs(total, total, null));
                Console.WriteLine("A完成");
            })).Start(CancellationToken.None);

            manager.Add(new SimplyProgressive(100, (e, token) =>
            {
                var total = 100;
                var value = 0;
                var r     = new Random();
                while (value < 100)
                {
                    Thread.Sleep(r.Next(200, 800));
                    value += r.Next(1, 30);
                    e.Report(new ProgressValueChangedEventArgs(total, Math.Min(total, value), null));
                }
                e.Report(new ProgressValueChangedEventArgs(total, total, null));
                Console.WriteLine("B完成");
            })).Start(CancellationToken.None);
            manager.Add(new SimplyProgressive(100, (e, token) =>
            {
                var total = 100;
                var value = 0;
                var r     = new Random();
                while (value < 100)
                {
                    Thread.Sleep(r.Next(200, 800));
                    value += r.Next(1, 30);
                    e.Report(new ProgressValueChangedEventArgs(total, Math.Min(total, value), null));
                }
                e.Report(new ProgressValueChangedEventArgs(total, total, null));
                Console.WriteLine("C完成");
            })).Start(CancellationToken.None);
            manager.Add(new SimplyProgressive(100, (e, token) =>
            {
                var total = 100;
                var value = 0;
                var r     = new Random();
                while (value < 100)
                {
                    Thread.Sleep(r.Next(200, 800));
                    value += r.Next(1, 30);
                    e.Report(new ProgressValueChangedEventArgs(total, Math.Min(total, value), null));
                }
                e.Report(new ProgressValueChangedEventArgs(total, total, null));
                Console.WriteLine("D完成");
            })).Start(CancellationToken.None);

            manager.ProgressValueChanged += Manager_ProgressValueChanged;

            manager.Start(CancellationToken.None).Wait();
            Console.WriteLine("完成");
            Console.ReadLine();
        }