Timer problem

G

Guest

Hi

i have function like above

Public Sub halytystutkinta()
Dim ds As New DataSet
ds = dl2.HaeHalytys()
Dim onkohal As Int16
onkohal = ds.Tables(0).Rows(0).Item("onkohalytys")
halid = ds.Tables(0).Rows(0).Item("halid")
If onkohal = 1 Then
Beep()
Label2.Text = "Halytys, halytys"
Image1.DataBind()
Beep()
End If
End Sub

and i try to use that function with timer like this

Private Sub OnTimer(ByVal source As Object, ByVal e As System.Timers.ElapsedEventArgs)
otakuva()
End Sub

Private Sub KaynnistaPalvelu()
AddHandler aTimer.Elapsed, AddressOf OnTimera

aTimer.Interval = 20000
aTimer.Enabled = True
end sub

but that doesnt not work
but if i call if call function halytystutkinta
like above it works

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
halytystutkinta()
End Sub

it is asp.net application
 
H

Hans Kesting

see inline

Antti Laakso said:
Hi

i have function like above

Public Sub halytystutkinta()
Dim ds As New DataSet
ds = dl2.HaeHalytys()
Dim onkohal As Int16
onkohal = ds.Tables(0).Rows(0).Item("onkohalytys")
halid = ds.Tables(0).Rows(0).Item("halid")
If onkohal = 1 Then
Beep()

Note: Beep (IF it works) would be a server-side function
Label2.Text = "Halytys, halytys"
Image1.DataBind()
Beep()
End If
End Sub

and i try to use that function with timer like this

Private Sub OnTimer(ByVal source As Object, ByVal e As System.Timers.ElapsedEventArgs)
otakuva()

Where is this function "otakuva" declared? Shouldn't it be "halytystutkinta" ?
End Sub

Private Sub KaynnistaPalvelu()
AddHandler aTimer.Elapsed, AddressOf OnTimera

Is "OnTimerA" a typo in the post? I think you mean "OnTimer".
aTimer.Interval = 20000
aTimer.Enabled = True
end sub

but that doesnt not work
but if i call if call function halytystutkinta
like above it works

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
halytystutkinta()
End Sub

it is asp.net application

Do you define the timer in an aspx page? That will NOT work as the lifetime
of that page (class) is one request. The next request will use a fresh class
where the timer will be reset. So the timer never fires!
It IS possible to use a timer, but (for asp.net) only in Global.asax.

What are you trying to do with this timer? Why are you using it?

Hans Kesting
 
G

Guest

Hans Kesting said:
see inline



Note: Beep (IF it works) would be a server-side function


Where is this function "otakuva" declared? Shouldn't it be "halytystutkinta" ?
it's a different function

Is "OnTimerA" a typo in the post? I think you mean "OnTimer". there is two timers


Do you define the timer in an aspx page? That will NOT work as the lifetime
of that page (class) is one request. The next request will use a fresh class
where the timer will be reset. So the timer never fires!
It IS possible to use a timer, but (for asp.net) only in Global.asax.

What are you trying to do with this timer? Why are you using it?

yes in aspx page. when timer fires it should call webservice which accesses a database and returns a dataset which contains information about alarms. i'll need to get that data from webservice about every 10seconds
 
H

Hans Kesting

yes in aspx page. when timer fires it should call webservice which accesses a database and returns a dataset which contains
information about alarms. i'll need to get that data from webservice about every 10seconds
Then that's the problem. The aspx page is finished in milliseconds so the timer gets destroyed long
before it can fire.

Possibly you can change the timer to client-side, using a <meta http-equiv=refresh content=10> tag in the html to
refresh the page every 10 seconds. In the page get the data immediately to build html to
send back to the browser.

Hans Kesting
 
M

M. Posseth

i once wrote a e-mail system that i wanted to be a-synchronous

i.o.w. i did not want the aspx page to wait untill the e-mail was generated
and send ( inmediate response back to the user )

what i did was the folowing

i added a standard module , declared a public class with properties and a
method sendmail

my aspx page received the parameters from the web , i passed these
parameters to the class module ( the parameters were e-mail adress to send
to , the message etc etc etc )

at last i called the method sendmail wich started a timer with delay of 500
miliseconds , when the timer triggered it would generate and send the e-mail

this did the trick for me ,,,,

what i wanted to say with this story is that it sure is possible to use a
timer in ASP.NET pages however they should be called from global code

M. Posseth [MCP]




accesses a database and returns a dataset which contains
information about alarms. i'll need to get that data from webservice about every 10seconds

Then that's the problem. The aspx page is finished in milliseconds so the timer gets destroyed long
before it can fire.

Possibly you can change the timer to client-side, using a <meta
http-equiv=refresh content=10> tag in the html to
 
G

Guest

Thank's for help!

Hans Kesting said:
information about alarms. i'll need to get that data from webservice about every 10seconds

Then that's the problem. The aspx page is finished in milliseconds so the timer gets destroyed long
before it can fire.

Possibly you can change the timer to client-side, using a <meta http-equiv=refresh content=10> tag in the html to
refresh the page every 10 seconds. In the page get the data immediately to build html to
send back to the browser.

Hans Kesting
 
G

Guest

Thank's for help!

M. Posseth said:
i once wrote a e-mail system that i wanted to be a-synchronous

i.o.w. i did not want the aspx page to wait untill the e-mail was generated
and send ( inmediate response back to the user )

what i did was the folowing

i added a standard module , declared a public class with properties and a
method sendmail

my aspx page received the parameters from the web , i passed these
parameters to the class module ( the parameters were e-mail adress to send
to , the message etc etc etc )

at last i called the method sendmail wich started a timer with delay of 500
miliseconds , when the timer triggered it would generate and send the e-mail

this did the trick for me ,,,,

what i wanted to say with this story is that it sure is possible to use a
timer in ASP.NET pages however they should be called from global code

M. Posseth [MCP]




accesses a database and returns a dataset which contains
information about alarms. i'll need to get that data from webservice about every 10seconds

Then that's the problem. The aspx page is finished in milliseconds so the timer gets destroyed long
before it can fire.

Possibly you can change the timer to client-side, using a <meta
http-equiv=refresh content=10> tag in the html to
refresh the page every 10 seconds. In the page get the data immediately to build html to
send back to the browser.

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top