By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,537 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,537 IT Pros & Developers. It's quick & easy.

how to active the FileSystemWatcher object????

P: n/a
Hi all,
I had made a program to watching files in my directory. I had used a
instance of FileSystemWatcher to do my work.And I had add some events of the
FileSystemWatcher , 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 FileSystemWatcher, 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.
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
EnableRaisingEvents property. The majority of the users of this API in
production
scenarios want to configure the object once, and then enable/disable the event
notifications as needed for performance reasons. I remember some mail about
specific scenarios when I was working on the .NET QuickStarts, but I couldn't
tell
you more precisely why they changed the API to have this property false by
default.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Jet Leung" <xi**@163.net> wrote in message
news:e9*************@tk2msftngp13.phx.gbl...
Hi all,
I had made a program to watching files in my directory. I had used a
instance of FileSystemWatcher to do my work.And I had add some events of the
FileSystemWatcher , 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 FileSystemWatcher, 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.

Nov 16 '05 #2

P: n/a
Hi jet,

Here is some code that is working in a similar environment.
Take a look that all this service does depend of the FileSystemWatcher
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 DismexOrderDispatcher : System.ServiceProcess.ServiceBase
{

protected override void OnStart(string[] args)
{
// This trigger the static constructor of the DataProvider class
DataProvider.Callme();
}
}

public class DataProvider
{

static FileSystemWatcher watcher=null;
static public void callme(){}
//This function "watch" a directory waiting for orders to arrive
public static void WatchOrdersFolder()
{
try
{
if ( watcher!=null) return;
watcher = new FileSystemWatcher();

watcher.Path = Config.ImportStorageFolder;
watcher.NotifyFilter = NotifyFilters.FileName
|NotifyFilters.CreationTime;
watcher.Filter = "*.flag";

// Add event handlers.
watcher.Created += new FileSystemEventHandler( AddedOrderFile);
watcher.EnableRaisingEvents = true;
}
catch(Exception ex)
{
Logger.CreateLog( "Error in WatchOrdersFolder e.m:" + ex.Message + "
e.ST:" + ex.StackTrace, System.Diagnostics.EventLogEntryType.Error );
}

}

static DataProvider()
{
try
{

//Set the FileFolderWatcher in the directory where the network deamon
put the files
WatchOrdersFolder();
}
catch( Exception e)
{
}

}

}

"Jet Leung" <xi**@163.net> wrote in message
news:e9*************@tk2msftngp13.phx.gbl...
Hi all,
I had made a program to watching files in my directory. I had used a
instance of FileSystemWatcher to do my work.And I had add some events of the FileSystemWatcher , 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 FileSystemWatcher, 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.

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.