控制台进度条
一、进度条 progress bar
- 安装
Nuget
包# 安装 Nuget 包 $ NuGet\Install-Package ShellProgressBar -Version 5.2.0
- 进度条
// 总数 int total = 100; // 进度条 using var pbar = new ProgressBar(total, $"(1/{total}) part(1) count({total})", new ProgressBarOptions { ForegroundColor = ConsoleColor.Blue, BackgroundColor = ConsoleColor.DarkBlue, ProgressCharacter = '─', CollapseWhenFinished = false }); // 记录进度 for (int i = 1; i <= total; i++) { pbar.Tick($"({i}/{100})"); }
- 下级进度条
// 总数 int total = 100; // 子进度总数 int child = 50; using (var pbar = new ProgressBar(total, $"(1/{total}) part(1) count({total})", new ProgressBarOptions { ForegroundColor = ConsoleColor.Blue, BackgroundColor = ConsoleColor.DarkBlue, ProgressCharacter = '─', CollapseWhenFinished = false })) { for (int i = 1; i <= total; i++) { for (int k = 1; k <= child; k++) { using var childBar = pbar.Spawn(1, $"{k}", new ProgressBarOptions { ForegroundColor = ConsoleColor.Green, BackgroundColor = ConsoleColor.DarkGreen, ProgressCharacter = '─', CollapseWhenFinished = false }); childBar.Tick(); pbar.Tick($"({i}/{100}) "); } } }
二、参考
- [官网]
如有帮助,欢迎转载,转载请注明原文链接:https://www.cnblogs.com/study10000/p/18080380