Global.aspx And FileSystemWatcher Problem

Discussion in 'ASP .Net' started by PadovaBoy, Jul 27, 2005.

  1. PadovaBoy

    PadovaBoy Guest

    Hi!
    I try to develop a simple system for monitoring a sub directory of a
    web site and remake an xml file every time a sub-dir change it's name.
    I don't wont to use a window.service because, i want to use the same
    system in many web-site.

    I have just write some line of code...but i have a problem:
    when i change the name of a file..i fire-up the Application_end events
    .... why?
    how i can meange the event of the filesystemwatcher?

    Tnx at all for any suggestion.
    Please ...escuse me for my english!!!
    Bye

    MyCode:

    [GLOBAL.ASAX]
    <%@ Application language="VB" inherits="myGlobal" Classname="MainApp"
    debug="true" %>

    [GLOBAL.VB]
    Protected Sub Application_start(sender As Object, e As EventArgs)

    'myWhatcher is the my object that will be store in the application

    Dim objMyWath as new myWhatcher(Server.MapPath("/repository/") )
    try
    Application.lock()
    Application.Add( "A_objMyWath" , objMyWath )
    catch ex as exception
    ...
    finally
    application.unlock()
    end try

    end sub

    Public Sub Application_End(sender As Object, e As EventArgs)
    Dim fsw = Application("A_objMyWath")
    Application.Remove( "A_objMyWath" )
    fsw.Dispose()
    end sub
    ----------------------------

    [myWhatcher.vb]
    public class myWhatcher
    'make a FileSystemWatcher with events..
    protected WithEvents fsw as new System.IO.FileSystemWatcher

    'the path to monitorize
    Public pathToAnalize as String

    Public Sub New(ByRef path As String)
    pathToAnalize = path
    'set the FileSystemWatcher object
    fsw.IncludeSubdirectories = True
    fsw.Path = pathToAnalize
    fsw.EnableRaisingEvents = True
    end sub

    'function fired-up by the event (rename)
    Private Sub fsw_OnRename(ByVal sender As System.Object, ByVal e As
    System.IO.RenamedEventArgs) Handles FSW.Renamed
    Dim swz As StreamWriter = New StreamWriter("L:\pippo\test.txt ")
    try
    If System.IO.Directory.Exists(e.FullPath) Then
    ... some operation
    End If
    catch ex as Exception
    end try

    End Sub

    public sub dispose()
    fsw.dispose()
    end sub

    end class
     
    PadovaBoy, Jul 27, 2005
    #1
    1. Advertising

  2. PadovaBoy

    Bruce Barker Guest

    asp.net also uses a filewatcher. when it detects a change, it recycles the
    site, thus your Application_end.

    a windows service is the best choice.

    -- bruce (sqlwork.com)

    "PadovaBoy" <> wrote in message
    news:...
    > Hi!
    > I try to develop a simple system for monitoring a sub directory of a
    > web site and remake an xml file every time a sub-dir change it's name.
    > I don't wont to use a window.service because, i want to use the same
    > system in many web-site.
    >
    > I have just write some line of code...but i have a problem:
    > when i change the name of a file..i fire-up the Application_end events
    > ... why?
    > how i can meange the event of the filesystemwatcher?
    >
    > Tnx at all for any suggestion.
    > Please ...escuse me for my english!!!
    > Bye
    >
    > MyCode:
    >
    > [GLOBAL.ASAX]
    > <%@ Application language="VB" inherits="myGlobal" Classname="MainApp"
    > debug="true" %>
    >
    > [GLOBAL.VB]
    > Protected Sub Application_start(sender As Object, e As EventArgs)
    >
    > 'myWhatcher is the my object that will be store in the application
    >
    > Dim objMyWath as new myWhatcher(Server.MapPath("/repository/") )
    > try
    > Application.lock()
    > Application.Add( "A_objMyWath" , objMyWath )
    > catch ex as exception
    > ...
    > finally
    > application.unlock()
    > end try
    >
    > end sub
    >
    > Public Sub Application_End(sender As Object, e As EventArgs)
    > Dim fsw = Application("A_objMyWath")
    > Application.Remove( "A_objMyWath" )
    > fsw.Dispose()
    > end sub
    > ----------------------------
    >
    > [myWhatcher.vb]
    > public class myWhatcher
    > 'make a FileSystemWatcher with events..
    > protected WithEvents fsw as new System.IO.FileSystemWatcher
    >
    > 'the path to monitorize
    > Public pathToAnalize as String
    >
    > Public Sub New(ByRef path As String)
    > pathToAnalize = path
    > 'set the FileSystemWatcher object
    > fsw.IncludeSubdirectories = True
    > fsw.Path = pathToAnalize
    > fsw.EnableRaisingEvents = True
    > end sub
    >
    > 'function fired-up by the event (rename)
    > Private Sub fsw_OnRename(ByVal sender As System.Object, ByVal e As
    > System.IO.RenamedEventArgs) Handles FSW.Renamed
    > Dim swz As StreamWriter = New StreamWriter("L:\pippo\test.txt ")
    > try
    > If System.IO.Directory.Exists(e.FullPath) Then
    > ... some operation
    > End If
    > catch ex as Exception
    > end try
    >
    > End Sub
    >
    > public sub dispose()
    > fsw.dispose()
    > end sub
    >
    > end class
     
    Bruce Barker, Jul 27, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tushar

    FileSystemWatcher Created() delay

    Tushar, Jan 20, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    5,804
    Tushar
    Jan 20, 2006
  2. Jon Maz
    Replies:
    3
    Views:
    7,672
    Jon Maz
    Oct 20, 2004
  3. J-T
    Replies:
    20
    Views:
    8,168
  4. Replies:
    3
    Views:
    408
    Darren Kopp
    Mar 13, 2006
  5. RaviNagam
    Replies:
    1
    Views:
    1,229
    BlackWasp
    Apr 11, 2008
Loading...

Share This Page