WebAPI Threading WebAPI Threading multithreading multithreading

WebAPI Threading


Use the Task Parallel Library (TPL) to spin off a new thread.

Task.Run(() => new Repository().computeLongFunction());return Request.CreateReponse(HttpStatusCode.Ok);


It doesn't look like computeLongFunction() returns anything, so try this:

Thread longThread = new Thread(() => new Repository().computeLongFunction());longThread.Start();return Request.CreateResponse(HttpStatusCode.Ok);

Declare the thread so that you will still be able to control its life-cycle.