Reputation: 135
I have create a rest api using api Controller in ASP.NET and performing some task that may take 10 minutes to finish task because user enter the time to finish that task. In this case I think multiple request can't be handle.
I am using this --
public class Controller : ApiController
{
[HttpGet]
[ActionName("APICall")]
public string API()
{
Rest y = new Rest();
return y.APiDATA();
}
}
my question is during performing this task when one more request come then does it create new thread for each request or not? if not then how to handle concurrent request . Please help me.
I am getting following error when calling url after deploy in IIS
{"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.","ExceptionType":"System.NullReferenceException","StackTrace":" at restapi.service.Rest.synthetic()\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.b__c(Object instance, Object[] methodParameters)\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"}
Upvotes: 0
Views: 4869
Reputation: 885
Each Web API request works its own separate thread and so multiple request will work. But you may face time out issue.
Regards
Abdul
Upvotes: 1
Reputation: 51
Each request that comes in will be on a separate thread (Task), but also each request that comes in will be on a new instance of your Controller class. However, you'll find that any client that doesn't get a response back within a small period of time (say 10 seconds, or maybe if you're lucky, 60 seconds), will consider it a timeout.
You probably need to park the processing somewhere else (say in a worker queue, and make sure you have a worker running that can handle it), and give back in your response a token they can use to poll for status. Or some other means of communicating to them when the job is done.
Upvotes: 1