Situation: In my web application, I trigger a lengthy operation using JavaScript that runs on the .NET2.0 backend. The call returns quickly with an operation ID while the operation continues in the background. These operations don't require much CPU power but involve slow network requests. Once the task is finished, I need to display the results on the web UI.
Query: How can I inform the user when the task is completed?
Potential Solutions:
Solution 1: I kick off the long-running task asynchronously from JavaScript and expect the return value to be the final outcome instead of just an operation ID. My AJAX framework manages everything smoothly, making life easier. However, this approach ties up a ThreadPool thread on the server for an extended period, which can lead to problems if multiple lengthy requests are made, potentially overwhelming the server's processing power.
Solution 2: Using the operation ID, I can periodically check with the server to see if the task is done. But this polling approach can be seen as a form of denial of service against my own server. There must be a more efficient Ajax-based solution to handle this issue, as it is a common challenge faced by developers.