Global.aspx And FileSystemWatcher Problem

P

PadovaBoy

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
 
B

Bruce Barker

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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top