Hi jet,
Here is some code that is working in a similar environment.
Take a look that all this service does depend of the FileSystemWatch er
events.
Note:
This may not compile as is as I removed lot of code !!
HTH,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
public class DismexOrderDisp atcher : System.ServiceP rocess.ServiceB ase
{
protected override void OnStart(string[] args)
{
// This trigger the static constructor of the DataProvider class
DataProvider.Ca llme();
}
}
public class DataProvider
{
static FileSystemWatch er watcher=null;
static public void callme(){}
//This function "watch" a directory waiting for orders to arrive
public static void WatchOrdersFold er()
{
try
{
if ( watcher!=null) return;
watcher = new FileSystemWatch er();
watcher.Path = Config.ImportSt orageFolder;
watcher.NotifyF ilter = NotifyFilters.F ileName
|NotifyFilters. CreationTime;
watcher.Filter = "*.flag";
// Add event handlers.
watcher.Created += new FileSystemEvent Handler( AddedOrderFile) ;
watcher.EnableR aisingEvents = true;
}
catch(Exception ex)
{
Logger.CreateLo g( "Error in WatchOrdersFold er e.m:" + ex.Message + "
e.ST:" + ex.StackTrace, System.Diagnost ics.EventLogEnt ryType.Error );
}
}
static DataProvider()
{
try
{
//Set the FileFolderWatch er in the directory where the network deamon
put the files
WatchOrdersFold er();
}
catch( Exception e)
{
}
}
}
"Jet Leung" <xi**@163.net > wrote in message
news:e9******** *****@tk2msftng p13.phx.gbl...
Hi all,
I had made a program to watching files in my directory. I had used a
instance of FileSystemWatch er to do my work.And I had add some events of
the FileSystemWatch er , for example onChange, onRename and so on.
And I had made this program as a windows service.As I know, if I delete a
file from my directory, this behavior will active this program and do
something what I want to do. But after I install this program as a windows
service and doing some behavior in the directory which I had set as the
property of the instance of FileSystemWatch er, this program will not do my
work for me.How can I solve it?
Acturaly, after I installed this program as the windows service and start
the debug in vs.net 2003 , it won't active the break point where I had set
the break point at the onChanged event. And I had added the handler of
this event.