当前位置: 首页>>代码示例>>C#>>正文


C# ProgressBar.Spawn方法代码示例

本文整理汇总了C#中ProgressBar.Spawn方法的典型用法代码示例。如果您正苦于以下问题:C# ProgressBar.Spawn方法的具体用法?C# ProgressBar.Spawn怎么用?C# ProgressBar.Spawn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProgressBar的用法示例。


在下文中一共展示了ProgressBar.Spawn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

        public Task Start(CancellationToken token)
        {
            var random = new Random();

            var numberOfSteps = 7;

            var overProgressOptions = new ProgressBarOptions
            {
                BackgroundColor = ConsoleColor.DarkGray,
            };

            using (var pbar = new ProgressBar(numberOfSteps, "overal progress", overProgressOptions))
            {
                var stepBarOptions = new ProgressBarOptions
                {
                    ForeGroundColor = ConsoleColor.Cyan,
                    ForeGroundColorDone = ConsoleColor.DarkGreen,
                    ProgressCharacter = '─',
                    BackgroundColor = ConsoleColor.DarkGray,
                    CollapseWhenFinished = false,

                } ;
                Parallel.For(0, numberOfSteps, (i) =>
                {
                    var workBarOptions = new ProgressBarOptions
                    {
                        ForeGroundColor = ConsoleColor.Yellow,
                        ProgressCharacter = '─',
                        BackgroundColor = ConsoleColor.DarkGray,
                    };
                    var childSteps = random.Next(1, 5);
                    using (var childProgress = pbar.Spawn(childSteps, $"step {i} progress", stepBarOptions))
                        Parallel.For(0, childSteps, (ci) =>
                        {
                            var childTicks = random.Next(50, 250);
                            using (var innerChildProgress = childProgress.Spawn(childTicks, $"step {i}::{ci} progress", workBarOptions))
                            {
                                for (var r = 0; r < childTicks; r++)
                                {
                                    innerChildProgress.Tick();
                                    Program.BusyWait(50);
                                }
                            }
                            childProgress.Tick();
                        });

                    pbar.Tick();
                });
            }
            return Task.FromResult(1);
        }
开发者ID:codejnki,项目名称:shellprogressbar,代码行数:51,代码来源:DeeplyNestedProgressBarTreeExample.cs

示例2: InnerProgressBars

        private static void InnerProgressBars(ProgressBar pbar)
        {
            var innerProgressBars = Enumerable.Range(0, new Random().Next(2, 6))
                .Select(s => pbar.Spawn(new Random().Next(2, 5), $"inner bar {s}"))
                .ToList();

            var maxTicks = innerProgressBars.Max(p => p.MaxTicks);

            for (var ii = 0; ii < maxTicks; ii++)
            {
                foreach (var p in innerProgressBars)
                {
                    InnerInnerProgressBars(p);
                    p.Tick();
                }

                Thread.Sleep(4);
            }
            foreach (var p in innerProgressBars) p.Dispose();
        }
开发者ID:codejnki,项目名称:shellprogressbar,代码行数:20,代码来源:NestedProgressBarPerStepProgress.cs


注:本文中的ProgressBar.Spawn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。