Skip to content

Worker

Namespace: MQTT_Receiver_Worker

Background worker service for handling MQTT message receiving operations.
Implements a long-running service that subscribes to MQTT topics and processes messages.

public class Worker : Microsoft.Extensions.Hosting.BackgroundService, Microsoft.Extensions.Hosting.IHostedService, System.IDisposable

Inheritance Object → BackgroundService → Worker

Implements IHostedService, IDisposable

Properties

ExecuteTask

public Task ExecuteTask { get; }

Property Value

Task

Constructors

Worker(ILogger<Worker>, IReceiver, IConnection)

Initializes a new instance of the Worker class.

public Worker(ILogger<Worker> logger, IReceiver receiver, IConnection connection)

Parameters

logger ILogger<Worker>

Logger for recording service events.

receiver IReceiver

MQTT receiver for subscribing to topics.

connection IConnection

Methods

ExecuteAsync(CancellationToken)

Executes the worker process, maintaining MQTT connection and subscribing to topics.
This is the main entry point for the background service execution.

protected Task ExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

Token that can be used to request cancellation of the operation.

Returns

A task representing the asynchronous operation.