What are some methods to alert my JS client without constant polling?

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.

Answer №1

If you're in need of a comet implementation for .NET, I highly recommend checking out WebSync. It's likely to meet your requirements perfectly.

Answer №2

When carried out correctly, polling should not significantly impact your server's performance. It is important to adjust the polling interval based on the specific requirements of your server tasks. For example, if you are aware that an operation typically takes a long time, wait at least 2 minutes before polling the server again. Additionally, it is recommended to use a larger interval, such as 10 seconds, to reduce traffic and the server time needed for processing requests. Utilizing a web service request or a custom handler can further help minimize the load on the server.

Answer №3

Reverse ajax, also known as comet, can be a valuable tool when dealing with a limited number of simultaneous clients. This innovative Ajax design pattern utilizes persistent HTTP connections to facilitate real-time communication between a web server and a browser. It enables data transmission from client to server and facilitates the delivery of server data back to the browser.

To learn more about reverse Ajax, check out http://en.wikipedia.org/wiki/Reverse_Ajax

I recently implemented reverse Ajax for a project, and it proved to be a highly effective solution. It might be just what you need for your requirements.

Answer №4

Have you considered using a hidden or small iframe to execute the time-consuming script, with JavaScript checking only the iframe's content? For example, the script could write an ID to the iframe upon completion.

Answer №5

In the past, I've followed the same route as your second option. Implementing a setTimeout function can help in controlling the frequency of your polling intervals, such as setting it to every 30 seconds.

Answer №6

The ICEfaces Framework is known for its AJAX Push technology, supporting Scalable Asynchronous Request Processing on popular application servers such as Jetty, Tomcat, and Glassfish.

Even though it's Java-related, it could assist in optimizing search terms for Google.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a Circle with Pixi.js v4 and Typerscript in IONIC 2

I have been attempting to create a custom class in TypeScript that utilizes PIXI.js to draw circles. Below is the code for my home.ts class: import { Component, ViewChild, ElementRef } from '@angular/core'; import { NavController } from 'i ...

Ways to verify the $window variable in ng-if or ng-show

One variable named variable1 has been declared, and I am looking to validate this variable across all pages using ng-if or ng-show. ...

Is there a glitch in the `Random` class in .Net?

As I was reviewing a question discussing the flawed implementation of the Fisher-Yates shuffling algorithm, I noticed that an incorrect implementation can result in bias. The two algorithms in question are: private Random _random = new Random(); public i ...

Open the CSV document

Why am I receiving an error stating ./vacancy-data.csv cannot be found when attempting to pass the csv file into the csvtojson npm package? The csv file is located in the same directory as the code below: var express = require('express'), route ...

Encountering the error message "This expression cannot be invoked" within a Typescript React Application

I'm working on separating the logic from the layout component in my Typescript React Application, but I suspect there's an issue with the return type of my controller function. I attempted to define a type to specify the return type, but TypeScr ...

Combine two elements together and display the outcome in json form

There are two objects that need to be summed up and returned in the same format as the original objects stored in a local file. The first JSON: { "data": [{ "x": "Q1 (J, F, M)", "y": [100, 500, 0], "tooltip": "this is tooltip" }, { "x": "Q2(A, M, ...

Using Django to store form information in the database and then fetching it with ajax functionality

I am looking to implement a feature where users can save details in a database and retrieve them back on the same page using Ajax. Below is the code snippet for your reference. I would appreciate any ideas or suggestions you may have. models.py class Per ...

Stop Ajax from activating jQuery function

Upon examining our Drupal site, we discovered a straightforward jQuery script that inserts a div class containing content: (function($) { Drupal.behaviors.myHelpText = { attach: function (context, settings) { //code begins //adjusting placeholder ...

Safari and Chrome are directing Angular Http Post requests to different URLs

Using the Angular framework and the $http directive to make a post request to our API endpoint works fine in Chrome, but I'm encountering an issue in Safari. Below is the code snippet from my Api factory: assignments: function(csv) { var deferred = ...

Using Typescript to pass a property as one of the keys in an object's list of values

In my React Native project, I need to pass a string value from one component to another. The different options for the value can be found in the ScannerAction object: export const ScannerAction = { move: 'move', inventory: 'inventory&apo ...

Is there a way to programmatically switch a mobile device to desktop view using HTML or JavaScript code?

I recently made some updates to my website, but the mobile view is not as polished as I would like it to be. I attempted to modify the code myself, but it has been challenging, especially since I did not originally develop the front-end. Does anyone know ...

Alert when clicking on Intent sends incorrect information to Activity

In my app, I am utilizing newIntent to correctly pass the taskId when a notification is clicked. The following snippet shows the code within the onReceive() function of my broadcast receiver: Intent newIntent = new Intent(context, TaskActivity.class); ...

There appears to be an issue with the functionality of the external CSS pathway

placeholder image hereplaceholder image hereplaceholder image here I'm encountering a problem and struggling to identify the mistake in my current approach. ...

Navigating to a new URL after submitting a form in React

Hello, I am new to React and have created a form that successfully sends data to Firebase. However, after submitting the form, I would like to redirect to /thankyou.html which is outside of the React app. Can someone please guide me on how to achieve this ...

Default value automatically changes the hashed URL in Backbone.js

Issue: I am facing a problem where after going to step 2, the "start" route becomes active for some reason. How can I address this problem? Here is the scenario: I start from step one -> move to step 2 -> the step2view is rendered, but then it immed ...

Harmonize the timing of three ajax requests

Is there a way to simultaneously display data from three AJAX requests that are fired one after another? I want to echo back all the data at the same time. $.ajax ({ type: "POST", url: "page1.php", data: "var1=" + var1, suc ...

Angular ng-bind-html directive allows you to bind HTML content to an

I am attempting to utilize $interpolate and ng-bind-html in order to bind the data from my scope variable to an html string as outlined in this solution. However, I have encountered an issue where the ng-bind-html result does not update when the value of m ...

Is there a way to define a variable that is accessible everywhere but only for the duration of a single REST request

After some consideration, I have come to question my current approach to this problem and would like to explain my intentions. Within my JWT token, there is a UserId property that I need to access on multiple REST endpoints for DB queries. To achieve thi ...

Saving large data in NodeJS using MongoDB and Mongoose in a non-blocking manner

Currently, I am in the midst of developing a straightforward application utilizing NodeJS, ExpressJS (with EJS), MongoDB, and Mongoose. Here's a synopsis of the issue at hand that requires some recommendations: Situation 1) Triggered by a specific e ...

Are you familiar with using double conditional rendering in a React application?

Currently, I am in the process of creating a small clothing store application using React as a way to expand my skills. One feature I have implemented is a filter by price section. However, I am looking for a solution to handle cases where no items fall wi ...