Simulate a Windows Service to create automation on server. Application_Start doesn't appear to fire?
===

I am trying to set up some automated functions to do various things, having been pointed in the direction of this:

http://www.codeproject.com/Articles/12117/Simulate-a-Windows-Service-using-ASP-NET-to-run-sc

I have followed the steps in that article as far as creating a single automated function (I've not gone into the job-queue extension they suggest yet as I'm just trying to get one thing at a time to work!)

I prefer to write in VB, so have converted it all. Here's the code which sits in my `global.asax` file:

    Public Class [Global]
        Inherits System.Web.HttpApplication
    
        Private Const DummyCacheItemKey As String = "GagaGuguGigi"
        Private Const DummyPageUrl As String = "MY_LOCATION/dummyForScheduling.aspx"
        
        Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
            RegisterCacheEntry()
        End Sub
    
        Private Function RegisterCacheEntry() As Boolean
            If HttpContext.Current.Cache(DummyCacheItemKey) IsNot Nothing Then
                Return False
            End If
            HttpContext.Current.Cache.Add(DummyCacheItemKey, "Test", Nothing, DateTime.MaxValue, TimeSpan.FromMinutes(2), CacheItemPriority.Normal, New CacheItemRemovedCallback(AddressOf CacheItemRemoved))
            Return True
        End Function
    
        Public Sub CacheItemRemoved(key As String, value As Object, reason As CacheItemRemovedReason)
            System.Diagnostics.Debug.WriteLine("Cache item callback: " & DateTime.Now.ToString())
            HitPage() ' loads dummy page to trigger a new cache item
            ' Do the service works
            DoWork()
        End Sub
    
        Protected Sub Application_BeginRequest(sender As [Object], e As EventArgs)
            ' If the dummy page is hit, then it means we want to add another item in cache

            If HttpContext.Current.Request.Url.ToString() = DummyPageUrl Then
                ' Add the item in cache and when succesful, do the work.
                RegisterCacheEntry()
            End If
        End Sub

        Sub DoWork()
            Dim objWriter As New StreamWriter(HttpContext.Current.Server.MapPath("/test.txt"))
            objWriter.WriteLine("Cache Callback: {0}" & (DateTime.Now).ToString)
            objWriter.Close()
        End Sub
    
        Private Sub HitPage()
            Dim client As New WebClient()
            client.DownloadData(DummyPageUrl)
        End Sub

    End Class

My page `dummyForScheduling.aspx` is simply a blank page which does nothing at all except allow the server to know a page is called (see the article)

In the Sub `doWork()` I am simply trying to write a line to a text file with the current date and time.

I am expecting to be able to view this text file in my browser, refresh it every two minutes and see an updated date in there, this is all I am trying to do at this stage.

A bit of Googling and SO searching came up with:

http://stackoverflow.com/questions/2440264/simulate-windows-service-with-asp-net

and then 

http://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

Which also point to other peoplpe trying to achieve this same effect.

I tried the shorter code from the SO blog file, but still nothing.

In either case, which ever code I use, nothing happens.

I mean, nothing at all, there are no errors, no Log entries that I can see, and no alterations to my currently blank `test.txt` file.

Am I missing something?

I am assuming the `global.asax` events are auto-wired up? I have `AutoEventWireup` set to false in my `config` file, is this what's stopping it?

**(Using .NET 2.0 by the way)**