How can I stop Settimeout on C#

Asked

Viewed 312 times

0

Hello, How can I stop the execution of Setimeout created in javascript only in C#? I Gero several PDF through this method.

Below is the script:

  function geracao(formulario) {


        window.setTimeout(function () {


            document.getElementById('<%=btn_PDFSIM.ClientID%>').click();


        }, 5000);
    }

  • 1

    There is no way to stop setTimeout because it only runs 1 time. You could stop him with clearTimeout() if he was making some kind of loop, and that you only get on the client side through the JS itself.

  • The Javascript code runs on the client side, specifically within the context of the browser used to access the site, which will have its own engine for interpreting the script. C# in this case would run on the server side. There is no way the server-side code converses with the client-side, let alone interact with the timers created by the browser engine that is accessing the site. At least I don’t see how it could happen!

1 answer

-1

You have two ways to do this. The first would be to poole to see if you can stop setTimeout by ordering at some API endpoint.

The second way would be using Signalr (I prefer Signalr because it works as an abstraction, it can do both pooling and websockets, etc).

You can find an example of Signalr here:

https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/tutorial-getting-started-with-signalr

sorry for the lack of accent, I do not live in Brazil and I am on an international keyboard. I will modify when I have the chance

Browser other questions tagged

You are not signed in. Login or sign up in order to post.