1

I have a web api like this:

public async Task<IHttpActionResult> PostTest(Model model)
{
    db.UserOrders.Add(model);
    await db.SaveChangesAsync();
    await PushUtils.SendPush("title" , "message"); // heavy task
    return Ok();
}


In this method the user has to wait until the heavy task is executed.
Is there any way to execute this task after returning value to the user?

Roham Rafii
  • 2,929
  • 7
  • 35
  • 49
ReZa
  • 1,273
  • 2
  • 18
  • 33
  • 2
    this colud help you..http://stackoverflow.com/questions/25274096/how-to-answer-a-request-but-continue-processing-code-in-webapi – Dhiren Patel Apr 15 '17 at 12:43

1 Answers1

0

I Used Hangfire :

public async Task<IHttpActionResult> PostTest(Model model)
{
    db.UserOrders.Add(model);
    await db.SaveChangesAsync();

    BackgroundJob.Schedule(
    () => PushUtils.SendPush("title" , "message"),
    TimeSpan.FromSeconds(7));

    return Ok();
}
ReZa
  • 1,273
  • 2
  • 18
  • 33