1

Does WebAPI have any built in support to fire off some work and return immediately to the caller with an acknowledgement. I am looking to build a data processing server which has some long running processes that need to be ran. The client never expects the results straight away and can query for them later.

With this being the case I am looking for a way to fire off some work in such a way that wont block the controller from returning.

1 Answer 1

3

There's nothing in WebAPI keeping you from starting off some background work and returning immediately. So you could have an action implementated like this:

public HttpResponseMessage Post()
{
     Task.Factory.StartNew(() => DoWork());
     return new HttpResponseMessage(HttpStatusCode.Accepted);
}

This is just a simple example, but you would probably want to track the Task in some kind of dictionary, so you could return the results when the client queries for them later.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.