Asp.net Timer
-
Hi All, Im triyng to use the System.Timers.Timer control in my page. In de button click eventhandler i have this code: System.Timers.Timer myTimer = new System.Timers.Timer(); myTimer.Interval = 1000; myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed); myTimer.Enabled = true; protected void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //do test Label1.Text = "a"; } The problem is that nothing happens ofter clicking the button. What is wrong here? Thanks.
-
Hi All, Im triyng to use the System.Timers.Timer control in my page. In de button click eventhandler i have this code: System.Timers.Timer myTimer = new System.Timers.Timer(); myTimer.Interval = 1000; myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed); myTimer.Enabled = true; protected void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //do test Label1.Text = "a"; } The problem is that nothing happens ofter clicking the button. What is wrong here? Thanks.
NewToAspDotNet wrote:
What is wrong here?
You don't understand how web applications work. There is no state. They are stateless. The page exists only for the briefest moment while the request is handled. After that it is unloaded from memory. Your timer now has nothing to time.
Recent blog posts: *SQL Server / Visual Studio install order *Installing SQL Server 2005 on Vista *Crazy Extension Methods Redux * Mixins My Blog
-
NewToAspDotNet wrote:
What is wrong here?
You don't understand how web applications work. There is no state. They are stateless. The page exists only for the briefest moment while the request is handled. After that it is unloaded from memory. Your timer now has nothing to time.
Recent blog posts: *SQL Server / Visual Studio install order *Installing SQL Server 2005 on Vista *Crazy Extension Methods Redux * Mixins My Blog
His username is 'NewToAspDotnet' and he has been a member since 2004. And check out his profile page http://www.codeproject.com/script/Membership/Profiles.aspx?mid=1251994[^]. He has asked a question on his own profile.
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
All the world's a stage, And all the men and women merely players. They have their exits and their entrances; And one man in his time plays many parts... --William Shakespeare -
Hi All, Im triyng to use the System.Timers.Timer control in my page. In de button click eventhandler i have this code: System.Timers.Timer myTimer = new System.Timers.Timer(); myTimer.Interval = 1000; myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed); myTimer.Enabled = true; protected void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //do test Label1.Text = "a"; } The problem is that nothing happens ofter clicking the button. What is wrong here? Thanks.