フッターコンテンツにスキップ
.NETヘルプ

Hangfire .NET Core (開発者向けの仕組み)

現代のアプリケーション開発では、大量のワークロードを処理するためにバックグラウンドタスクを処理する必要があることがよくあります。 そのようなシナリオでは、複数のジョブを実行できるバックグラウンドジョブハンドラーが必要です。 C# .NET Core アプリケーション向けのバックグラウンドジョブハンドラーの1つに Hangfire があります。このブログでは、Hangfire バックグラウンドジョブの管理方法と、IronPDF for PDF Generation のような他のパッケージと組み合わせてバックグラウンドで PDF ドキュメントを生成する方法について学びます。

Hangfire は、ASP.NET Core または .NET Core 6 Web API アプリケーションでバックグラウンド処理を実装するのを簡単にし、バックグラウンドジョブの管理と実行に信頼性が高く柔軟なフレームワークを提供します。 Hangfire は NuGet パッケージとして利用可能で、以下のように .NET CLI を使用してインストールできます:

dotnet add package Hangfire --version 1.8.6

.NET Core Web API での実装

Hangfire について学ぶために、簡単な .NET Core API アプリケーションを作成し、CLI を使用して Hangfire をインストールしましょう。

dotnet new webapi -n HangfireDemo
cd HangfireDemo
dotnet build
dotnet add package Hangfire --version 1.8.6
dotnet build
dotnet new webapi -n HangfireDemo
cd HangfireDemo
dotnet build
dotnet add package Hangfire --version 1.8.6
dotnet build
SHELL

ここでは .NET CLI を使用してシンプルな天気予報 REST API を作成します。 最初の行は API エンドポイントを実行するための HangfireDemo という名前の .NET Core Web API プロジェクトを作成します。 2行目で、新しく作成したフォルダー "HangfireDemo" に移動し、プロジェクトをビルドします。 次に、プロジェクトに Hangfire NuGet パッケージを追加し、再度ビルドします。 その後、任意のエディタ(Visual Studio 2022 や JetBrains Rider など)でプロジェクトを開くことができます。 この時点でプロジェクトを実行すると、Swagger が以下のように表示されます。

Hangfire .NET Core (開発者向けの動作方法): 図 1 - Swagger

ここでは、日付、概要、気温を返す天気 GET API を見ることができます。

Hangfire .NET Core (開発者向けの動作方法): 図 2 - 天気 GET API

それでは、Hangfire バックグラウンドジョブプロセッサを追加しましょう。 Visual Studio でプロジェクトを開きます。

Hangfire ジョブプロセッサを追加

アプリケーションで Hangfire を設定します。通常は Startup.cs ファイルで行います。これにはジョブストレージの設定と Hangfire サーバーの初期化が含まれます。

// Startup.cs
using Hangfire;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Add Hangfire services and use SQL Server as storage option
        services.AddHangfire(config => config.UseSqlServerStorage("your_connection_string"));
        services.AddHangfireServer();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        // Use Hangfire Server and Dashboard for monitoring and managing jobs
        app.UseHangfireServer();
        app.UseHangfireDashboard();
        // Your other configuration settings
    }
}
// Startup.cs
using Hangfire;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Add Hangfire services and use SQL Server as storage option
        services.AddHangfire(config => config.UseSqlServerStorage("your_connection_string"));
        services.AddHangfireServer();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        // Use Hangfire Server and Dashboard for monitoring and managing jobs
        app.UseHangfireServer();
        app.UseHangfireDashboard();
        // Your other configuration settings
    }
}
' Startup.cs
Imports Hangfire

Public Class Startup
	Public Sub ConfigureServices(ByVal services As IServiceCollection)
		' Add Hangfire services and use SQL Server as storage option
		services.AddHangfire(Function(config) config.UseSqlServerStorage("your_connection_string"))
		services.AddHangfireServer()
	End Sub

	Public Sub Configure(ByVal app As IApplicationBuilder, ByVal env As IHostingEnvironment)
		' Use Hangfire Server and Dashboard for monitoring and managing jobs
		app.UseHangfireServer()
		app.UseHangfireDashboard()
		' Your other configuration settings
	End Sub
End Class
$vbLabelText   $csharpLabel

ConfigureServices メソッドは、Hangfire の新しいジョブを保存するためのストレージを追加するために使用されます。 ここでは、SQL Server データベースが使用されています。 SQL Server 接続文字列は、"your_connection_string" に置き換える必要があります。 Hangfire.InMemory を使用してインメモリストレージとしても利用できます。

dotnet add package Hangfire.InMemory --version 0.6.0

そして、以下のものに置き換えます:

services.AddHangfire(configuration => { configuration.UseInMemoryStorage(); });
services.AddHangfire(configuration => { configuration.UseInMemoryStorage(); });
services.AddHangfire(Sub(configuration)
	configuration.UseInMemoryStorage()
End Sub)
$vbLabelText   $csharpLabel

バックグラウンドジョブを作成

バックグラウンドジョブとして実行したいメソッドを定義します。 これらのメソッドは、引数のないコンストラクタを持つクラスのスタティックメソッドまたはインスタンスメソッドである必要があります。 ジョブは再帰ジョブとして実行することも、複数のジョブを同時に実行することもできます。

public class MyBackgroundJob
{
    public void ProcessJob()
    {
        // Background job logic, can be a recurring job or multiple jobs
        Console.WriteLine("Background job is running...");
    }
}
public class MyBackgroundJob
{
    public void ProcessJob()
    {
        // Background job logic, can be a recurring job or multiple jobs
        Console.WriteLine("Background job is running...");
    }
}
Public Class MyBackgroundJob
	Public Sub ProcessJob()
		' Background job logic, can be a recurring job or multiple jobs
		Console.WriteLine("Background job is running...")
	End Sub
End Class
$vbLabelText   $csharpLabel

ジョブをキューに入れる

Hangfire API を使用してバックグラウンドジョブをキューに入れます。 バックグラウンドジョブを特定の時間に、遅延後に、または定期的に実行するようにスケジュールできます。

// Enqueue a job to run immediately
BackgroundJob.Enqueue<MyBackgroundJob>(x => x.ProcessJob());

// Schedule a job to run after a 5-minute delay
BackgroundJob.Schedule<MyBackgroundJob>(x => x.ProcessJob(), TimeSpan.FromMinutes(5));

// Schedule a recurring job using a job ID
RecurringJob.AddOrUpdate<MyBackgroundJob>("jobId", x => x.ProcessJob(), Cron.Daily);
// Enqueue a job to run immediately
BackgroundJob.Enqueue<MyBackgroundJob>(x => x.ProcessJob());

// Schedule a job to run after a 5-minute delay
BackgroundJob.Schedule<MyBackgroundJob>(x => x.ProcessJob(), TimeSpan.FromMinutes(5));

// Schedule a recurring job using a job ID
RecurringJob.AddOrUpdate<MyBackgroundJob>("jobId", x => x.ProcessJob(), Cron.Daily);
' Enqueue a job to run immediately
BackgroundJob.Enqueue(Of MyBackgroundJob)(Function(x) x.ProcessJob())

' Schedule a job to run after a 5-minute delay
BackgroundJob.Schedule(Of MyBackgroundJob)(Function(x) x.ProcessJob(), TimeSpan.FromMinutes(5))

' Schedule a recurring job using a job ID
RecurringJob.AddOrUpdate(Of MyBackgroundJob)("jobId", Function(x) x.ProcessJob(), Cron.Daily)
$vbLabelText   $csharpLabel

Hangfire ダッシュボードとサーバー

リアルタイムのジョブ監視のために Configure メソッドに Hangfire ダッシュボードとサーバーを追加することができます。

// Run Hangfire server and dashboard
app.UseHangfireServer();
app.UseHangfireDashboard();
// Run Hangfire server and dashboard
app.UseHangfireServer();
app.UseHangfireDashboard();
' Run Hangfire server and dashboard
app.UseHangfireServer()
app.UseHangfireDashboard()
$vbLabelText   $csharpLabel

サーバーは ConfigureServices に追加することも可能です。

services.AddHangfireServer();
services.AddHangfireServer();
services.AddHangfireServer()
$vbLabelText   $csharpLabel

忘れっぽいジョブ

// Fire and forget jobs are executed only once and almost immediately after creation.
var jobId = BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-forget!")); // Job ID for fire and forget job
// Fire and forget jobs are executed only once and almost immediately after creation.
var jobId = BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-forget!")); // Job ID for fire and forget job
' Fire and forget jobs are executed only once and almost immediately after creation.
Dim jobId = BackgroundJob.Enqueue(Sub() Console.WriteLine("Fire-and-forget!")) ' Job ID for fire and forget job
$vbLabelText   $csharpLabel

定期的なジョブ

// Recurring jobs fire many times based on a specified CRON schedule.
RecurringJob.AddOrUpdate("myrecurringjob", () => Console.WriteLine("Recurring!"), Cron.Daily);
// Recurring jobs fire many times based on a specified CRON schedule.
RecurringJob.AddOrUpdate("myrecurringjob", () => Console.WriteLine("Recurring!"), Cron.Daily);
' Recurring jobs fire many times based on a specified CRON schedule.
RecurringJob.AddOrUpdate("myrecurringjob", Sub() Console.WriteLine("Recurring!"), Cron.Daily)
$vbLabelText   $csharpLabel

遅延ジョブ

// Delayed jobs are executed only once but after a specified interval.
var jobId = BackgroundJob.Schedule(() => Console.WriteLine("Delayed!"), TimeSpan.FromDays(7));
// Delayed jobs are executed only once but after a specified interval.
var jobId = BackgroundJob.Schedule(() => Console.WriteLine("Delayed!"), TimeSpan.FromDays(7));
' Delayed jobs are executed only once but after a specified interval.
Dim jobId = BackgroundJob.Schedule(Sub() Console.WriteLine("Delayed!"), TimeSpan.FromDays(7))
$vbLabelText   $csharpLabel

継続

// Continuation jobs are executed once their parent jobs have completed.
BackgroundJob.ContinueJobWith(jobId, () => Console.WriteLine("Continuation!"));
// Continuation jobs are executed once their parent jobs have completed.
BackgroundJob.ContinueJobWith(jobId, () => Console.WriteLine("Continuation!"));
' Continuation jobs are executed once their parent jobs have completed.
BackgroundJob.ContinueJobWith(jobId, Sub() Console.WriteLine("Continuation!"))
$vbLabelText   $csharpLabel

バッチジョブ

// Batch is a group of background jobs created atomically and considered as a single entity.
var batchId = BatchJob.StartNew(x =>
{
    x.Enqueue(() => Console.WriteLine("Job 1"));
    x.Enqueue(() => Console.WriteLine("Job 2"));
});
// Batch is a group of background jobs created atomically and considered as a single entity.
var batchId = BatchJob.StartNew(x =>
{
    x.Enqueue(() => Console.WriteLine("Job 1"));
    x.Enqueue(() => Console.WriteLine("Job 2"));
});
' Batch is a group of background jobs created atomically and considered as a single entity.
Dim batchId = BatchJob.StartNew(Sub(x)
	x.Enqueue(Sub() Console.WriteLine("Job 1"))
	x.Enqueue(Sub() Console.WriteLine("Job 2"))
End Sub)
$vbLabelText   $csharpLabel

バッチ継続ジョブ

// Batch continuation is fired when all background jobs in a parent batch are finished.
BatchJob.ContinueBatchWith(batchId, x =>
{
    x.Enqueue(() => Console.WriteLine("Last Job"));
});
// Batch continuation is fired when all background jobs in a parent batch are finished.
BatchJob.ContinueBatchWith(batchId, x =>
{
    x.Enqueue(() => Console.WriteLine("Last Job"));
});
' Batch continuation is fired when all background jobs in a parent batch are finished.
BatchJob.ContinueBatchWith(batchId, Sub(x)
	x.Enqueue(Sub() Console.WriteLine("Last Job"))
End Sub)
$vbLabelText   $csharpLabel

ダッシュボード

Hangfire ダッシュボードでは、バックグラウンドジョブのすべての情報を見つけることができます。 これは OWIN ミドルウェアとして記述されており(OWIN に詳しくない場合でも心配ありません)、ASP.NET、ASP.NET MVC、Nancy、ServiceStack アプリケーションに接続することができ、OWIN Self-Host 機能を使用して、コンソールアプリケーションまたは Windows サービス内でダッシュボードをホストすることができます。

ダッシュボードが有効になっている場合、/hangfire/ 拡張子でアクセスできます。 このダッシュボードでは、バックグラウンドで実行されているジョブを管理したり、バックグラウンドジョブをスケジュールしたり、頻繁に忘れてしまうジョブを管理したりできます。 ジョブはジョブIDを使用して識別できます。

ライブ処理

Hangfire .NET Core (開発者向けの動作方法): 図 3 - ジョブのライブ処理

成功したジョブ

成功したジョブを以下に表示します。

Hangfire .NET Core (開発者向けの動作方法): 図 4 - 成功したジョブ

スケジュールされたジョブ

Hangfire .NET Core (開発者向けの動作方法): 図 5 - スケジュールされたジョブ

アプリケーションが実行すると、Hangfire は設定された設定に基づいてバックグラウンドジョブの処理を行います。

Remember to check the Hangfire documentation for more advanced configuration options and features: Hangfire Documentation and complete code can be found on GitHub Hangfire Demo.

Introducing IronPDF

IronPDF for .NET PDF Generation is a NuGet package from NuGet パッケージであり、PDF ドキュメントの読み取りと生成を支援します。 スタイル情報を含む簡単にフォーマットされたドキュメントを PDF に変換できます。 IronPDF は HTML コンテンツから簡単に PDF を生成できます。 URL から HTML をダウンロードし、PDF を生成することができます。

IronPDF の主な魅力は、レイアウトとスタイルを保持する HTML から PDF への変換 機能です。 ウェブコンテンツから PDF を作成でき、レポート、請求書、ドキュメントに最適です。 この機能は、HTML ファイル、URL、および HTML 文字列を PDF に変換することをサポートします。

using IronPdf;

class Program
{
    static void Main(string[] args)
    {
        var renderer = new ChromePdfRenderer();

        // Convert HTML String to PDF
        var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>";
        var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent);
        pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf");

        // Convert HTML File to PDF
        var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file
        var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath);
        pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf");

        // Convert URL to PDF
        var url = "http://ironpdf.com"; // Specify the URL
        var pdfFromUrl = renderer.RenderUrlAsPdf(url);
        pdfFromUrl.SaveAs("URLToPDF.pdf");
    }
}
using IronPdf;

class Program
{
    static void Main(string[] args)
    {
        var renderer = new ChromePdfRenderer();

        // Convert HTML String to PDF
        var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>";
        var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent);
        pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf");

        // Convert HTML File to PDF
        var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file
        var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath);
        pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf");

        // Convert URL to PDF
        var url = "http://ironpdf.com"; // Specify the URL
        var pdfFromUrl = renderer.RenderUrlAsPdf(url);
        pdfFromUrl.SaveAs("URLToPDF.pdf");
    }
}
Imports IronPdf

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim renderer = New ChromePdfRenderer()

		' Convert HTML String to PDF
		Dim htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"
		Dim pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent)
		pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf")

		' Convert HTML File to PDF
		Dim htmlFilePath = "path_to_your_html_file.html" ' Specify the path to your HTML file
		Dim pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath)
		pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf")

		' Convert URL to PDF
		Dim url = "http://ironpdf.com" ' Specify the URL
		Dim pdfFromUrl = renderer.RenderUrlAsPdf(url)
		pdfFromUrl.SaveAs("URLToPDF.pdf")
	End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF を始める

IronPDF ライブラリをインストール

NuGet パッケージマネージャーを使用してインストール

NuGet パッケージマネージャーを使用して Hangfire .NET プロジェクトに IronPDF を統合するには、以下の手順に従います:

  1. Visual Studio を開き、ソリューションエクスプローラーでプロジェクトを右クリックします。
  2. コンテキストメニューから「NuGet パッケージの管理...」を選択します。
  3. 「参照」タブに移動し、IronPDF を検索します。
  4. 検索結果から IronPDF ライブラリを選択し、「インストール」ボタンをクリックします。
  5. いずれかのライセンス契約の同意プロンプトに同意します。

パッケージマネージャーコンソールを使用する方が好みの場合、次のコマンドを実行します:

Install-Package IronPdf

これにより、あなたのプロジェクトに IronPDF が取得され、インストールされます。

NuGetウェブサイトを使用してインストール

特徴、互換性、追加のダウンロードオプションを含む IronPDF の詳細な概要については、NuGet ウェブサイトの IronPDF ページ https://www.nuget.org/packages/IronPdf を訪問してください。

DLL を使用してインストール

また、DLL ファイルを使用して IronPDF をプロジェクトに直接組み込むことができます。この IronPDF ダイレクトダウンロード から DLL を含む ZIP ファイルをダウンロードし、解凍してプロジェクトに DLL を含めます。 さあ、アプリケーションを変更して背景処理ジョブを追加し、ウェブサイトを PDF ファイルとしてダウンロードしましょう。

IronPDF には、URL からウェブサイトをダウンロードし、PDF ドキュメントとして保存する組み込みのメソッドがあります。

namespace HangfireDemo.Core;

public class PdfGenerationJob
{
    public void Start(string website)
    {
        // Create a PDF from any existing web page
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        PdfDocument pdf = renderer.RenderUrlAsPdf(website);
        var filePath = AppContext.BaseDirectory + "result.pdf";
        pdf.SaveAs(filePath);
    }
}
namespace HangfireDemo.Core;

public class PdfGenerationJob
{
    public void Start(string website)
    {
        // Create a PDF from any existing web page
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        PdfDocument pdf = renderer.RenderUrlAsPdf(website);
        var filePath = AppContext.BaseDirectory + "result.pdf";
        pdf.SaveAs(filePath);
    }
}
Namespace HangfireDemo.Core

	Public Class PdfGenerationJob
		Public Sub Start(ByVal website As String)
			' Create a PDF from any existing web page
			Dim renderer As New ChromePdfRenderer()
			Dim pdf As PdfDocument = renderer.RenderUrlAsPdf(website)
			Dim filePath = AppContext.BaseDirectory & "result.pdf"
			pdf.SaveAs(filePath)
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

ジョブでこの方法を使用して、指定された場所にダウンロードして保存します。 このバックグラウンドジョブは、複数のウェブサイト URL を受け取り、それらを PDF として保存するように変更できます。 さて、PDF 生成およびダウンロード API を公開するためにコントローラーを追加しましょう。

ここでは、バックグラウンドジョブを開始するためにウェブサイト URL を取得し、ダウンロードを開始する API と、結果の PDF をダウンロードするもう1つの API を作成しました。

using Hangfire;
using HangfireDemo.Core;
using Microsoft.AspNetCore.Mvc;

namespace HangfireDemo.Controllers;

[ApiController]
[Route("[controller]")]
public class PdfGeneratorController : ControllerBase
{
    [HttpGet("request", Name = "Start PDF Generation")]
    public void Start([FromQuery] string websiteUrl)
    {
        BackgroundJob.Enqueue<PdfGenerationJob>(x => x.Start(websiteUrl));
    }

    [HttpGet("result", Name = "Download PDF Generation")]
    public IActionResult WebResult()
    {
        var filePath = AppContext.BaseDirectory + "result.pdf";
        var stream = new FileStream(filePath, FileMode.Open);
        return new FileStreamResult(stream, "application/octet-stream") { FileDownloadName = "website.pdf" };
    }
}
using Hangfire;
using HangfireDemo.Core;
using Microsoft.AspNetCore.Mvc;

namespace HangfireDemo.Controllers;

[ApiController]
[Route("[controller]")]
public class PdfGeneratorController : ControllerBase
{
    [HttpGet("request", Name = "Start PDF Generation")]
    public void Start([FromQuery] string websiteUrl)
    {
        BackgroundJob.Enqueue<PdfGenerationJob>(x => x.Start(websiteUrl));
    }

    [HttpGet("result", Name = "Download PDF Generation")]
    public IActionResult WebResult()
    {
        var filePath = AppContext.BaseDirectory + "result.pdf";
        var stream = new FileStream(filePath, FileMode.Open);
        return new FileStreamResult(stream, "application/octet-stream") { FileDownloadName = "website.pdf" };
    }
}
Imports Hangfire
Imports HangfireDemo.Core
Imports Microsoft.AspNetCore.Mvc

Namespace HangfireDemo.Controllers

	<ApiController>
	<Route("[controller]")>
	Public Class PdfGeneratorController
		Inherits ControllerBase

		<HttpGet("request", Name := "Start PDF Generation")>
		Public Sub Start(<FromQuery> ByVal websiteUrl As String)
			BackgroundJob.Enqueue(Of PdfGenerationJob)(Function(x) x.Start(websiteUrl))
		End Sub

		<HttpGet("result", Name := "Download PDF Generation")>
		Public Function WebResult() As IActionResult
			Dim filePath = AppContext.BaseDirectory & "result.pdf"
			Dim stream = New FileStream(filePath, FileMode.Open)
			Return New FileStreamResult(stream, "application/octet-stream") With {.FileDownloadName = "website.pdf"}
		End Function
	End Class
End Namespace
$vbLabelText   $csharpLabel

API は以下のように示されています。 Hangfire .NET Core (開発者向けの動作方法): 図 7 - PDFジェネレーター API

結果は次のようになります:

Hangfire .NET Core (開発者向けの動作方法): 図 8 - 出力

上記のコードがウォーターマークなしで動作するためには、ライセンスキーが必要です。

ライセンス (無料トライアル利用可能)

開発者は IronPDF フリートライアル に登録することでトライアルライセンスを入手できます。 トライアルライセンスにはクレジットカードは不要です。 メールアドレスを提供して、フリートライアルに登録できます。 Hangfire と IronPDF は、バックグラウンドで PDF を生成およびダウンロードするための素晴らしい組み合わせです。

結論

Hangfire は長時間実行タスクの効率的な処理を実現し、IronPDF は PDF 生成のための柔軟で使いやすいソリューションを提供します。 IronPDF ドキュメント を訪問して、IronPDF について詳しく学びましょう。 また、Iron Software Product Suite の他のツールも探索して、コーディングスキルを強化し、現代のアプリケーション要件を満たしてください。

Also, explore other tools from the Iron Software Product Suite which can enhance your coding skills and meet modern application requirements.

よくある質問

.NET Core の Hangfire とは?

Hangfire は、ASP.NET Core または .NET Core 6 アプリケーションでバックグラウンド処理を簡素化するフレームワークです。バックグラウンドジョブの管理と実行に信頼性と柔軟性を備えたソリューションを提供します。

.NET Core アプリケーションに Hangfire をインストールするにはどうすればよいですか?

Hangfire は NuGet パッケージとしてインストールできます。.NET CLI で次のコマンドを使用して追加できます:dotnet add package Hangfire --version 1.8.6

Hangfire がサポートするバックグラウンドジョブの種類は何ですか?

Hangfireは、Fire-and-forgetジョブ、遅延ジョブ、定期ジョブ、および継続ジョブを含むさまざまなタイプのバックグラウンドジョブをサポートします。

.NET Core アプリケーションで Hangfire を構成するにはどうすればよいですか?

Hangfire は Startup.cs ファイルで構成され、ジョブストレージを設定し、Hangfire サーバーを初期化します。通常、Hangfire サービスを追加し、SQL Server またはインメモリストレージを設定することが含まれます。

Hangfire ダッシュボードとは何ですか?

Hangfire ダッシュボードは、バックグラウンドジョブの監視および管理のためのツールです。ライブログに関する情報、成功したジョブ、およびスケジュールされたジョブを提供し、Web インターフェースを通じてアクセス可能です。

Hangfire を使用してバックグラウンドジョブを作成するにはどうすればよいですか?

バックグラウンドジョブは、ジョブとして実行したいメソッドを定義し、それを Hangfire API を使用してキューに入れることによって作成できます。ジョブは、即座に実行するようにスケジュールすることも、遅延後に実行するようにスケジュールすることも、定期的な basis でスケジュールすることもできます。

.NET Core を使用してバックグラウンドで PDF 生成タスクを実行するにはどうすればよいですか?

HTML から PDF への変換をサポートする PDF ライブラリを使用して、バックグラウンドで PDF 生成タスクを実行できます。これは、Hangfire のようなバックグラウンドジョブ処理フレームワークと統合して、HTML コンテンツからの PDF 作成を自動化できます。

.NET における PDF 生成ライブラリのいくつかの機能は何ですか?

PDF 生成ライブラリは、HTML 文字列、HTML ファイル、および URL を PDF に変換できます。レイアウトとスタイルを保持し、Web コンテンツからのレポート、請求書、および文書の生成に役立ちます。

.NET プロジェクトに PDF 生成ライブラリをインストールするにはどうすればよいですか?

PDF 生成ライブラリは、Visual Studio の NuGet パッケージマネージャーを使用して、または特定のコマンドを使用してパッケージマネージャーコンソール経由でインストールできます。また、ライブラリの Web サイトから DLL を直接ダウンロードしてインストールすることもできます。

透かし無しで PDF 生成ライブラリを使用するには何が必要ですか?

「Hangfire .NET Core(開発者向けの動作方法)」という記事は、ASP.NET Core または .NET Core 6 Web API アプリケーションでの Hangfire の実装についての詳細なガイドです。

.NET Core で Hangfire と PDF 生成ツールを統合するにはどうすればよいですか?

.NET Core で Hangfire と PDF 生成ツールを統合するには、HTML から PDF への変換を行う PDF 生成ライブラリを使用してバックグラウンドジョブを設定します。これにより、アプリケーションでのドキュメントの自動作成と管理が可能になります。

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。