0

I need Implement a method that does not expect the return of a call to another method to return OK. How to do this?

i try use 'await' but this wait a finish to return "OK"

[WebMethod] //WebServiceMethod
public string ImportaDadosPosLeilaoValores(string fileName)
{
    // this call may take several minutes and should NOT be expected
    ImportaDados(fileName);
    return "OK - Received";     // immediately
}

A call to the method that IMMEDIATELY returns an OK informing the receiving of the file, in the background, the called method will work until finished and will not return anything when finished

Ludvig
  • 3
  • 3
  • Hmm, no question? Good. Please proceed with your exercise. Also note that your current code example suffers from an infinite recursion, essentially causing a stack overflow (pun intended) when called... –  May 30 '19 at 17:22
  • The good news is it probably won't take several minutes. – Scott Hannen May 30 '19 at 17:26
  • Look into the System.Threading namespace. You should be able to spawn a new thread to run `ImportaDados`. – DeadZone May 30 '19 at 20:33
  • File upload should drop the file onto a file share or a storage location someplace. Build a small console app that monitors that location and reacts, processing it. Long running processing jobs don’t belong on the web server app. You’re just consuming threads for a long period of time and introduces a vulnerability that can be exploited. If the job runs for a long time, I can spam upload you (unless you have protections) and exhaust your thread pool. – Johnathon Sullinger May 31 '19 at 02:20

0 Answers0