What is the right script to handle only one async action? For example, I need to import a large file, and during import I need to disable this option to ensure that the second import will not start.
What comes to mind is that:
[HttpPost]
public async Task<HttpResponseMessage> ImportConfigurationData()
{
if (HttpContext.Current.Application["ImportConfigurationDataInProcess"] as bool? ?? false)
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Task still running");
HttpContext.Current.Application["ImportConfigurationDataInProcess"] = true;
string root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
await Request.Content.ReadAsMultipartAsync(provider);
HttpContext.Current.Application["ImportConfigurationDataInProcess"] = false;
Request.CreateResponse(HttpStatusCode.OK, true)
}
But this seems like a very hard-coded solution. What is the right way to handle this? Another thing is that he does not work properly on the client side, he is still waiting for an answer. So the user can simply send this file to the server and not wait until he finishes, but reload the page after sending the file to the server, without waiting for the material to finish await.
source
share