I am developing a database file system.It includes a multi-directory watcher which is a windows service and which uses the file system watcher class from .net.
I want to run each watcher class on separate thread.Thread can not be extended in .net because as it is "Sealed". What I want is, run all the methods of my watcher class in the related thread. How can I achieve this?
EDIT -
Following is my base watcher class.
public abstract class WatcherBase
{
private IWatchObject _watchObject;
public WatcherBase() { }
public WatcherBase(IWatchObject watchObject, bool canPauseAndContinue)
{
_watchObject = watchObject;
CanPauseAndContinue = canPauseAndContinue;
}
public bool CanPauseAndContinue { get; set; }
public IWatchObject ObjectToWatch
{
get
{
return _watchObject;
}
}
public abstract void Start();
public abstract void Pause();
public abstract void Continue();
public abstract void Stop();
}
Following is my directory watcher class extended from the WatcherBase class
namespace RankFs.WatcherService
{
public class DirectoryWatcher : WatcherBase
{
private WatchDirectory _directoryToWatch;
private FileSystemWatcher _watcher;
public DirectoryWatcher(WatchDirectory directory, bool CanPauseAndContinue)
:base(directory ,CanPauseAndContinue)
{
_directoryToWatch = directory;
_watcher = new FileSystemWatcher(_directoryToWatch.Path);
_watcher.IncludeSubdirectories = _directoryToWatch.WatchSubDirectories;
_watcher.Created +=new FileSystemEventHandler(Watcher_Created);
//_watcher.Changed +=new FileSystemEventHandler(Watcher_Changed);
_watcher.Deleted +=new FileSystemEventHandler(Watcher_Deleted);
_watcher.Renamed +=new RenamedEventHandler(Watcher_Renamed);
}
public WatchDirectory DirectoryToWatch
{
get
{
return _directoryToWatch;
}
}
public override void Start()
{
_watcher.EnableRaisingEvents = true;
}
public override void Pause()
{
_watcher.EnableRaisingEvents = false;
}
public override void Continue()
{
_watcher.EnableRaisingEvents = true;
}
public override void Stop()
{
_watcher.EnableRaisingEvents = false;
}
private void Watcher_Created(object sender, FileSystemEventArgs e)
{
// adds a new file entry to database
}
private void Watcher_Deleted(object sender, FileSystemEventArgs e)
{
//updates the database(deleted file)
}
private void Watcher_Renamed(object sender, RenamedEventArgs e)
{
//updates the database(renamed file)
}
} }
I am stuck at this point.Please help me.