ASP.NET Application and FileSystemWatcher

J

J-T

Thanks Kevin for all the helps and follow ups.I appreciate it.
I got it finally up and working.Here is the code

**********My Global.asax :

IFPWatcherComponent ifpWacher=new IFPWatcherComponent(
ConfigurationSettings.AppSettings["MonitorPath"],
int.Parse(ConfigurationSettings.AppSettings["SimultaniousNumberOfFiles"]));

Authorization.Current.Initialize();
try
{
Application.Lock();
Application.Add("IFPWatcherComponent",ifpWacher);
}
finally
{
Application.UnLock();

**********Class:

public class IFPWatcherComponent: Timer
{

private string mDir="";
private string mirrorDir="";
private int iCount=1;


// Monitor directory
public string monitorDirectory
{
get { return this.mDir; }
set { this.mDir= value; }
}

// interval
public double timerInterval
{
get { return this.Interval; }
set { this.Interval= value; }
}


public IFPWatcherComponent(string MonitorPath,int FileCounts)
{

this.monitorDirectory=MonitorPath;
this.fileCounts=FileCounts;

try
{
//Check to see if Web.config has appropriate settings
if (this.monitorDirectory.Trim().Length==0 ) return;

// Make a reference to a Montitor directory.
DirectoryInfo diMonitor = new DirectoryInfo(this.monitorDirectory);
// Create the directory only if it does not already exist.
if (diMonitor.Exists == false)
diMonitor.Create();

this.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
this.Interval=this.timerInterval;
this.Enabled=true;
}
catch
{
throw;
}
}

private void OnTimedEvent(object source, ElapsedEventArgs e)
{
//do whatever you want here
}


}
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,600
Members
45,179
Latest member
pkhumanis73
Top