I am developing a database file system. It includes a multi-frame observer, which is a Windows service and that uses a file observer class from .net.
I want to run each observer class in a separate thread. Work cannot be extended to .net because it is "sealed." I want all the methods of my watcher class to be executed in the corresponding thread. How can I achieve this?
EDIT -
Below is my base observer 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();
}
Below is my observer class extended from 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.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)
{
}
private void Watcher_Deleted(object sender, FileSystemEventArgs e)
{
}
private void Watcher_Renamed(object sender, RenamedEventArgs e)
{
}
} }
I am stuck at this point. Please help me.