The time it takes for PageMethod to be received by code behind is not consistent

53 Views Asked by At

I am quite new to webpage development.

I have a ASP .NET Web Application. On my webpage, I have several controls, that when clicked, will call a PageMethod to the code behind. My concern is, when I click any of these controls, and the respective PageMethod is fired, the amount of time it takes until the WebMethod in the code behind get hit is not consistent. Sometimes it will happen within 1s, but sometimes it will take 15s. The PageMethod always fires immediately after the click. It is not like these PageMethods are being called quickly either, so I wouldn't think any backup/lock is happening. I would like it so my PageMethods are always received by the code behind somewhere around 1s. I can't seem to find anyone else with this issue. I am hoping someone can explain/guide me to a solution. Below is a code snippet of one of these click instances:

Javascript side:

<canvas id="DisplayCanvas" onclick="onRadarEchoClick(event)"> </canvas>

    function onRadarEchoClick(e) {
                        //code stuff.
    
                        //Queue up radar echo click to be processed.
                        radarEchoQueue.push([convertedX, convertedY, e.button]);
        
                        var radarEchoInterval = setInterval(function () {
                            if (radarEchoReady) {
                                radarEchoReady = false;
                                clearInterval(radarEchoInterval);
                                const click = radarEchoQueue.shift();
                                PageMethods.OnRadarEchoClick(click[0], click[1], click[2], onRadarEchoSuccess);
                            }
                        }, 100);
                    }
        
                    function onRadarEchoSuccess() {
                        //The server has successfully processed the last radar echo click.
                        radarEchoReady = true;
                    }

Code behind side (C#):

    [WebMethod]
            public static void OnRadarEchoClick(double xComponent, double yComponent, int button)
            {
                //code stuff.
                //There is where my breakpoint will take a random amount of time (1-15s) to be hit.
            }
0

There are 0 best solutions below