Your problem is that the timScheduledTask
is a location variable to the Application_Start
function. Once this function finishes, the instance of the timer is destroyed by the garbage collector. If you store the timer in a class variable you should be fine.
For example like this:
Public Class Foo
Private timScheduledTask As System.Timers.Timer
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
timScheduledTask = New System.Timers.Timer
timScheduledTask.Interval = 600 * 1000 //in milliseconds
timScheduledTask.Enabled = True
timScheduledTask.Start()
AddHandler timScheduledTask.Elapsed, AddressOf MyHelper
End Sub
Protected Sub MyHelper(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As DataSet = obj1.Dataset()
Dim onRemoveCallback As CacheItemRemovedCallback
_cache.Insert("ResultDataset", ds, New CacheDependency("C:\AspNetSql\Quotes.Quotations"), Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.[Default], onRemoveCallback)
End Sub
End Class
Or even like this:
Public Class Foo
Private WithEvents timScheduledTask As System.Timers.Timer
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
timScheduledTask = New System.Timers.Timer
timScheduledTask.Interval = 600 * 1000 //in milliseconds
timScheduledTask.Enabled = True
timScheduledTask.Start()
End Sub
Protected Sub MyHelper(ByVal sender As Object, ByVal e As EventArgs) Handles timScheduledTask.Elapsed
Dim ds As DataSet = obj1.Dataset()
Dim onRemoveCallback As CacheItemRemovedCallback
_cache.Insert("ResultDataset", ds, New CacheDependency("C:\AspNetSql\Quotes.Quotations"), Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.[Default], onRemoveCallback)
End Sub
End Class