dianaemanuel Posted March 6, 2015 at 10:46 AM Report Share #578855 Posted March 6, 2015 at 10:46 AM Boas, Eu queria saber como é que chamo uma função a cada 20 minutos e onde possa utilizar as minhas variáveis de sessão. Já fiz o seguinte código mas não funciona: System.Threading.Timer timer; public void Callback(object state) { Response.Write("The current time is " + DateTime.Now.ToString() + " - " + Session["UserID"].ToString()); } protected void Page_Init(object sender, EventArgs e) { timer = new System.Threading.Timer(Callback, null, TimeSpan.Zero, TimeSpan.FromMinutes(20)); } Link to comment Share on other sites More sharing options...
nelsonr Posted March 6, 2015 at 11:14 AM Report Share #578856 Posted March 6, 2015 at 11:14 AM Boas, não tens hipotese de usares a parte do cliente para fazer essa chamada? Tipo ter em javascript a executar um webservice? É que por default, caso não haja chamada pelo cliente, o servidor desliga o processo passados 20m. Link to comment Share on other sites More sharing options...
dianaemanuel Posted March 6, 2015 at 11:28 AM Author Report Share #578857 Posted March 6, 2015 at 11:28 AM Fiz assim e já funciona: <asp:Button ID="Button2" runat="server" Text="Call Button Click" Style="display:none" onclick="Button2_Click" /> $g(document).ready(function () { setInterval(function () { document.getElementById("Button2").click(); }, 1200000); }); protected void Button2_Click(object sender, EventArgs e) { Response.Write("The current time is " + DateTime.Now.ToString() + " - " + Session["UserID"].ToString()); } Obrigado. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now