Jump to content

chamar função a cada 20 minutos


dianaemanuel
 Share

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.