1
0

更新README

This commit is contained in:
2024-03-22 14:13:02 +08:00
parent 8dbe80a1a4
commit 78b4bc3792

View File

@@ -270,10 +270,39 @@ BackgroundJob.ContinueJobWith(jobid, () => Console.WriteLine("Continuations"));
### Progressing text console and show bar ### Progressing text console and show bar
使用 IPerformContextAccessor 從 Hangfire 的 PerformContext 取得進度管理的元件後,透過 Console 提供的擴充輸出到 GUI 管理介面。
``` ```
NUGET INSTALL Bonura.Hangfire.PerformContextAccessor -Version 1.3.3 NUGET INSTALL Bonura.Hangfire.PerformContextAccessor -Version 1.3.3
NUGET INSTALL Hangfire.Console -Version 1.4.3 NUGET INSTALL Hangfire.Console -Version 1.4.3
``` ```
![ProgressBar](HangfireResources/ProgressBar.jpg) ![ProgressBar](HangfireResources/ProgressBar.jpg)
Console 套件同時也提供格式化輸出字串的功能。
```
// 取得 Hangfire 的進程管理
var bar = context.WriteProgressBar();
context.WriteLine("The text color change to red");
context.SetTextColor(ConsoleTextColor.Red);
context.WriteLine("This progress is ready to start");
context.ResetTextColor();
// 使用 WithProgress 方法回報進程管理,任務的進度已更新
foreach (var i in Enumerable.Range(0, seconds).ToList().WithProgress(bar))
{
Thread.Sleep(1000);
}
context.SetTextColor(ConsoleTextColor.Green);
context.WriteLine("This progress has finished");
context.ResetTextColor();
```