Scheduled Task Question

Discussion in 'ASP.NET 2.0' started by R3dD0g, Feb 26, 2006.

  1. I need to automatically ftp the data collected into a file from a form. I looked at the scheduled task manager and decided that I could put the necessary code into the page_load event on a blank, unlinked page, then call the page with the scheduled task manager. I've got the code working and was about ready to hook it all up - when it occured to me.

    In the debug sessions the page is still running after the page_load event reaches end sub. I'm not real hot on webserver stuff, but it seems to me that page is tying up server resources. I don't want anybody to have to intervene through a browser to close the page.

    So, am I worrying about nothing? Or do I need to do something to close the app?
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    why don't you do this?

    Schedule a Windows Schedule on your local computer (where the file reside) and upload the file to the server. That is much cleaner and easier.

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. The data file is residing on Discount ASP servers. I need to get it from there to my local intranet. There will be a separate file for each day. I need more programmability to 'remember' which files have been transferred, etc than a local machine task can accomplish.

    What about the page? Will it still be consuming resources? I'm originally a windows programmer and have that concern drilled into me.
     
  4. its possible the page can remain in memory, it depends on how you code the application and what controls you are using.


    Joel Thoms

    DiscountASP.NET
    http://www.DiscountASP.NET
     
  5. I thought about putting a bunch of calls to <object>.dispose in the page_unload method. But, I'm still left with how do I call the unload method? I need some way for the page to release itself.

    What would putting Me.Dispose as the last line of the Page_Load method do?
     
  6. I want to write it such that it doesn't stay in memory.

    I'm not using any asp.net controls. It's a blank page. The code behind uses datasets, xmldatadatadocuments and streamwriters. The entire code is:

    Imports System.Data
    Imports System.IO.File
    Imports clsFTP

    Partial Class Secure_FTPApplicationFiles
    Inherits System.Web.UI.Page

    Dim ff As clsFTP.clsFTP
    Dim bSent As Boolean = False

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack And PreviousPage Is Nothing And Not IsCallback Then
    If Not FileIO.FileSystem.FileExists(Server.MapPath('~') & '\FTPApplicationFiles.xsd') And _
    Not FileIO.FileSystem.FileExists(Server.MapPath('~') & '\FTPApplicationFiles.xml') Then
    DefineDataSet()
    End If

    ff = New clsFTP.clsFTP('ftp....', '/.../', '...', '...', 80) 'this is a lightweight vb.net ftp class I found on DevX
    FindAppFiles()
    ff.CloseConnection()
    End Sub

    Private Sub DefineDataSet()
    Dim _ds As New DataSet('FTPApplicationFiles')

    Using _dt As New DataTable('SentApplicationFiles')
    Dim column As DataColumn

    column = New DataColumn
    column.DataType = System.Type.GetType('System.String')
    column.ColumnName = 'SentAppFileName'
    _dt.Columns.Add(column)

    column = New DataColumn
    column.DataType = Type.GetType('System.DateTime')
    column.ColumnName = 'SentDate'
    _dt.Columns.Add(column)

    column = New DataColumn
    column.DataType = System.Type.GetType('System.Int32')
    column.ColumnName = 'FileSize'
    _dt.Columns.Add(column)

    _ds.Tables.Add(_dt)
    End Using

    Using _dt As New DataTable('FoundApplicationFiles')
    Dim column As DataColumn

    column = New DataColumn
    column.DataType = System.Type.GetType('System.String')
    column.ColumnName = 'FoundAppFileName'
    _dt.Columns.Add(column)

    Dim keys(1) As DataColumn
    keys(0) = column
    _dt.PrimaryKey = keys

    _ds.Tables.Add(_dt)
    End Using

    _ds.WriteXmlSchema(Server.MapPath('~') & '\App_Data\FTPApplicationFiles.xsd')
    _ds.WriteXml(Server.MapPath('~') & '\App_Data\FTPApplicationFiles.xml')
    End Sub

    Private Sub FindAppFiles()
    Dim _ds As New DataSet('FTPApplicationFiles')
    _ds.ReadXmlSchema(Server.MapPath('~') & '\App_Data\FTPApplicationFiles.xsd')
    _ds.ReadXml(Server.MapPath('~') & '\App_Data\FTPApplicationFiles.xml')

    Dim _dt As DataTable = _ds.Tables('FoundApplicationFiles')

    For Each _foundFile As String In FileIO.FileSystem.GetFiles(Server.MapPath('~') & _
    '\ApplicationData', FileIO.SearchOption.SearchTopLevelOnly, 'STAR_*.xml')
    Try
    _dt.Rows.Add(FileIO.FileSystem.GetFileInfo(_foundFile.ToString).Name)
    SendFile(_foundFile.ToString, _ds.Tables('SentApplicationFiles'))
    Catch ex As System.Data.ConstraintException
    'to do: write error to server log
    End Try
    Next

    If bSent Then
    _ds.WriteXml(Server.MapPath('~') & '\App_Data\FTPApplicationFiles.xml', _
    XmlWriteMode.IgnoreSchema)
    End If
    End Sub

    Private Sub SendFile(ByVal sFile As String, ByRef _dt As DataTable)
    If (ff.Login() = True) Then
    ff.SetBinaryMode(True)

    ff.UploadFile(sFile)

    Dim _row As DataRow = _dt.NewRow
    _row.Item(0) = FileIO.FileSystem.GetFileInfo(sFile).Name
    _row.Item(1) = Date.Now
    _row.Item(2) = FileIO.FileSystem.GetFileInfo(sFile).Length
    _dt.Rows.Add(_row)
    End If

    bSent = True
    End Sub
    End Class

    Post Edited (R3dD0g) : 2/28/2006 4:34:37 AM GMT
     
  7. I'm not expert at VB, but if available, you could try calling the dispose method on your objects to explicitly set them to be garbage collected.
     
  8. So, I don't have to explicitly do anything to clean up after myself?

    Cool. /emoticons/yeah.gif

    Thanks.
     
  9. the unload method will be called automatically after it the render method, even if there is no browser connected to it.


    Joel Thoms

    DiscountASP.NET
    http://www.DiscountASP.NET
     

Share This Page