From 78b4bc3792dfc73196ce0099cfe222d0b5d977af Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 22 Mar 2024 14:13:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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