delamtangete
سه شنبه 08 مهر 1393, 09:39 صبح
من تابعی دارم که میخوام هر 1 ثانیه فراخوانی بشه
این کار رو داخل فایل Global.asax انجام دادم فقط بعد از چند دقیقه از کار می افته و تا زمانی که سایت باز نشه کار نمی کنه
اینم کد های داخل فایل هستش
Public Class Global_asax
Inherits System.Web.HttpApplication
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Application("ActiveUsers") = 0
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
Session.Timeout = 1
Application.Lock()
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.UnLock()
Dim myTimer As New System.Timers.Timer()
myTimer.Interval = 1000
myTimer.AutoReset = True
AddHandler myTimer.Elapsed, AddressOf myTimer_Elapsed
myTimer.Enabled = True
End Sub
Public Sub myTimer_Elapsed(ByVal source As Object, ByVal e As System.Timers.ElapsedEventArgs)
Dim JOB As New Job()
JOB.DoSomeWorkWithDB("New Server 1")
End Sub
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires upon attempting to authenticate the use
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
Application.Lock()
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.UnLock()
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application ends
End Sub
End Class
این کار رو داخل فایل Global.asax انجام دادم فقط بعد از چند دقیقه از کار می افته و تا زمانی که سایت باز نشه کار نمی کنه
اینم کد های داخل فایل هستش
Public Class Global_asax
Inherits System.Web.HttpApplication
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Application("ActiveUsers") = 0
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
Session.Timeout = 1
Application.Lock()
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.UnLock()
Dim myTimer As New System.Timers.Timer()
myTimer.Interval = 1000
myTimer.AutoReset = True
AddHandler myTimer.Elapsed, AddressOf myTimer_Elapsed
myTimer.Enabled = True
End Sub
Public Sub myTimer_Elapsed(ByVal source As Object, ByVal e As System.Timers.ElapsedEventArgs)
Dim JOB As New Job()
JOB.DoSomeWorkWithDB("New Server 1")
End Sub
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires upon attempting to authenticate the use
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
Application.Lock()
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.UnLock()
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application ends
End Sub
End Class