locked
How to automate VB.net action at a date-time with no user interaction. (i.e create a weekly report) RRS feed

  • Question

  • User1210767569 posted

    Question: How do I automate vb.net based on a timer with no user interaction

    Detail:

    I am looking to create a weekly report and email the client.

    I have a report that is generated manually with date select so all that code is sorted. The only part I have read alot about and am struggling to not find old articles on (http://www.codeproject.com/Articles/3990/Simple-Windows-Service-Sample) is the best way to schedule code to run once a week automatically.

    I use VB.net and have access to the SQL management and IIS. 

    Basically what is the best practise to do this, there seems to be a few global.asax ways but then that is reliant on visitors. 

    I have put some code below to show a bit of research! 

    <%@ Application Language="VB" %>
    <%@ Import Namespace="System.Threading" %>
    
    <script runat="server">
    
        Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs on application startup
            While True
                If DayOfWeek.thursday = DateTime.Now.DayOfWeek AndAlso 15 = DateTime.Now.Hour Then
                    Session.Item("Test") = "Between 3 and 4pm"
                Else
                     Session.Item("Test") = "Not between 3 and 4pm"
                End If
                ' Execute update here
    
                Thread.Sleep(TimeSpan.FromHours(1))
            End While
        End Sub
        
        Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs on application shutdown
        End Sub
            
        Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs when an unhandled error occurs
        End Sub
    
        Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs when a new session is started
        End Sub
    
        Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs when a session ends.
    SELECT distinct [userfirstname], [UserSurname] FROM [dbo].[tblResults] 
    
    where [ModuleDateStart] <= @dateStart and [ModuleDateStart] >= @dateEnd 
    
    GROUP BY [UserFirstName], [UserSurname] 
    
    order by [UserSurname] asc;

    ' Note: The Session_End event is raised only when the sessionstate mode ' is set to InProc in the Web.config file. If session mode is set to StateServer ' or SQLServer, the event is not raised. End Sub </script>

    the actual query...


    Thursday, September 5, 2013 11:39 AM

Answers

All replies