Any remaining background operations that the app is performing should be aborted.When cancellation is requested on the token: The cancellation token has a default five second timeout to indicate that the shutdown process should no longer be graceful. Implement IDisposable and finalizers (destructors) to dispose of any unmanaged resources. StopAsync contains the logic to end the background task. StopAsync(CancellationToken) is triggered when the host is performing a graceful shutdown.StartAsync should be limited to short running tasks because hosted services are run sequentially, and no further services are started until StartAsync runs to completion. The server is started and IApplicationLifetime.ApplicationStarted is triggered.The app's request processing pipeline is configured.StartAsync(CancellationToken) contains the logic to start the background task. The IHostedService interface defines two methods for objects that are managed by the host: An explicit package reference in the app's project file isn't required. For example, see the sample app's project file ( BackgroundTasksSample.csproj).įor web apps that use the SDK, the package is referenced implicitly from the shared framework. dotnet new worker -o ContosoWorkerĪn app based on the Worker Service template uses the SDK and has an explicit package reference to the package. A folder for the ContosoWorker app is created automatically when the command is executed. In the following example, a Worker Service app is created named ContosoWorker. Use the Worker Service ( worker) template with the dotnet new command from a command shell. Provide a name in the Project Name field.NET Core 3.1 or later for the Target Framework. In the Additional information dialog, Choose a Framework.Provide a project name in the Project name field or accept the default project name.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |