diff --git a/README.md b/README.md index 6715348..6ba5c90 100644 --- a/README.md +++ b/README.md @@ -270,10 +270,39 @@ BackgroundJob.ContinueJobWith(jobid, () => Console.WriteLine("Continuations")); ### Progressing text console and show bar +使用 IPerformContextAccessor 從 Hangfire 的 PerformContext 取得進度管理的元件後,透過 Console 提供的擴充輸出到 GUI 管理介面。 + ``` NUGET INSTALL Bonura.Hangfire.PerformContextAccessor -Version 1.3.3 NUGET INSTALL Hangfire.Console -Version 1.4.3 ``` -![ProgressBar](HangfireResources/ProgressBar.jpg) \ No newline at end of file +![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(); +``` \ No newline at end of file