Movatterモバイル変換


[0]ホーム

URL:


Skip to main contentSkip to in-page navigation

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

BackgroundService Class

Definition

Namespace:
Microsoft.Extensions.Hosting
Assembly:
Microsoft.Extensions.Hosting.Abstractions.dll
Package:
Microsoft.Extensions.Hosting.Abstractions v10.0.0
Source:
BackgroundService.cs
Source:
BackgroundService.cs
Source:
BackgroundService.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Base class for implementing a long runningIHostedService.

public ref class BackgroundService abstract : IDisposable, Microsoft::Extensions::Hosting::IHostedService
public abstract class BackgroundService : IDisposable, Microsoft.Extensions.Hosting.IHostedService
type BackgroundService = class    interface IHostedService    interface IDisposable
Public MustInherit Class BackgroundServiceImplements IDisposable, IHostedService
Inheritance
BackgroundService
Implements

Constructors

NameDescription
BackgroundService()

Initializes a new instance of theBackgroundService class.

Properties

NameDescription
ExecuteTask

Gets the Task that executes the background operation.

Methods

NameDescription
Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

ExecuteAsync(CancellationToken)

This method is called when theIHostedService starts. The implementation should return a task that representsthe lifetime of the long running operation(s) being performed.

StartAsync(CancellationToken)

Triggered when the application host is ready to start the service.

StopAsync(CancellationToken)

Triggered when the application host is performing a graceful shutdown.

Extension Methods

NameDescription
StartAndStopAsync(IHostedService, CancellationToken)

Starts and immediately stops the service.

Applies to

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?