Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Background Processing in Web API Call

RSS
Modified on Thu, May 29, 2025, 10:46 AM by Administrator Categorized as ASP·NET Web API

Overview

This article provides sample code for the use case where we want a Web API call to return immediately but continue with background processing.

Sample Code

[HttpPost]
public IActionResult DoBackgroundProcessing(
    [FromBody] MyRequest request
    )
{
    Response.OnCompleted(async () =>
    {
        await DoBackgroundTaskAsync(request);
    });

    return Accepted();
}

private async Task DoBackgroundTaskAsync(MyRequest request)
{
    // TODO
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2025, Patrick Jasinski.