Home » Asp.netRSS

Timer in asp.net via VB

Hi,

Is there any possibility to use Timer in Background of asp.net page? I need to always run the timer to monitor one field of table.

I was thinking to develop a small desktop application and run always on server, but it looks ugly idea if such kind of service can be done via asp.net it selef.

Please provide your ideas how it can be done?


Thank You


 

3 Answers Found

 

Answer 1

Hi, have you looked at using the Ajax timer  control? Take a look at this video tutorial here:

http://www.asp.net/ajax/videos/how-do-i-use-the-aspnet-ajax-timer-control

 

Answer 2

Hi,

Yes, you can create a Timer in background of ASP.NET. Please have a try on this sample.

Firstly create a new class called “MyTimer” then paste this code in the class file.

Imports System.Timers

Public NotInheritable Class MyTimer
    Private Sub New()
    End Sub
    ' Run the checking every minute
    Public Shared timer As New Timer(60000)

    ' Enable the timer to run
    Public Shared Sub StartRuning()
        AddHandler timer.Elapsed, AddressOf timer_Elapsed
        timer.Start()
    End Sub

    ' This method will be called every minute
    Private Shared Sub timer_Elapsed(ByVal sender As Object, ByVal e As ElapsedEventArgs)

        ' write code here to query or update database

    End Sub
End Class

Then write code in Global class to enable the Timer.

    ' This is Global.asax.vb
    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application is started
        MyTimer.StartRuning()
    End Sub

 

 

Answer 3

if you have access to the server, use scheduled tasks for running some services in regular intervals. In this case, you need to create a standalone application and make an exe out of it, then schedule it.


If you are hosting application with shared hosting environment, then can use the cache expiration and run the service on intervals..

see this article

http://www.beansoftware.com/ASP.NET-Tutorials/Scheduled-Tasks.aspx


 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter