473,387 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Windows Service using File System Watcher

I seem to remember using a walkthru in the early beta that demonstrated how
to create a Windows Service that would monitor events in a folder.
Can someone please direct me to an example of doing this?

Thanks,
Troy
Nov 15 '05 #1
1 10028
Thank you!
I will attempt to implement your guidance.

Troy
"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:eC**************@TK2MSFTNGP10.phx.gbl...
Hi Troy,

Here are codes snipets I'm using

protected override void OnStart(string[] args)

{

// TODO: Add code here to start your service.

//Start the listener thread

listenerThread = new Thread( new ThreadStart( ListenerMethod));

listenerThread.Start();

}

protected void ListenerMethod()

{

//In this form we have no control over the children threads

Thread workingthread;

//Create the FileWatcher objects

SetWatchers();

// ...... trimmed
}

// This function created the watchers , one of then watch the config file of the service, so I can change settings without stop/start the service. !!!!
public void SetWatchers()

{

try

{

Clientwatcher = new FileSystemWatcher();

Configwatcher = new FileSystemWatcher();
Clientwatcher.Path = Config.StorageFolder;

Clientwatcher.Filter = Config.ClientExportFile;

Configwatcher.Path = Config.StorageFolder;

Configwatcher.Filter = Config.ConfigExportFile;

/* Watch for changes in LastAccess and LastWrite times, and

the renaming of files or directories. */

Clientwatcher.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite ;

Configwatcher.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite ;

// Add event handlers.

Clientwatcher.Created += new FileSystemEventHandler( ClientFileUpdated);

Clientwatcher.Changed += new FileSystemEventHandler( ClientFileUpdated);

Configwatcher.Created += new FileSystemEventHandler( ConfigFileUpdated);

Configwatcher.Changed += new FileSystemEventHandler( ConfigFileUpdated);

//Activate them

Configwatcher.EnableRaisingEvents =

Productwatcher.EnableRaisingEvents = Clientwatcher.EnableRaisingEvents =
true;

}

catch( Exception e)

{

eventLog1.WriteEntry( "Error in SetWatchers : " + e.Message,
EventLogEntryType.Error);

}

}

// Now all you have to do is create the handlers.
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Troy Murphy" <tr**@solutionsoft.cc> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I seem to remember using a walkthru in the early beta that demonstrated

how
to create a Windows Service that would monitor events in a folder.
Can someone please direct me to an example of doing this?

Thanks,
Troy


Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: joel | last post by:
I created a service to watch the c: drive for the creation of exe's and write an event. The problem is anytime I create several vbs files as a test and then delete them, explorer.exe crashes. I think...
1
by: Rich Miller | last post by:
Previously posted on the VB newsgroup with no replies, so any ideas appreciated. I have written a service application in VB (VS.Net 2003). On start, the service creates an object that...
5
by: Belsam | last post by:
Hi all I need to create a windows service that will wait for a file to be copied somewhere, write it to the database, and then move the file to a storage area. I don't know when the file will...
3
by: Craig Thompson | last post by:
I've attempted to write a windows service that creates one FileSystemWatcher for each entry in a XML config file. Everything start perfrectly and runs as I expect for about 5 minutes and then...
1
by: Jack David | last post by:
How would I convert the following console app to a windows service?? using System; using System.IO; using FileProcessor;
1
by: Aaron | last post by:
I tried this with and without a timer, I got farther with a timer. THis code works just fine in a form but only gets as far as activating StartWatcher in the Win Service. protected override...
4
by: Primo | last post by:
Hi, This problem has been frustrating me for days and I hope you experts can help me out. I am trying to run a command, which I would normally run from the command line, from within my C#...
6
by: acool | last post by:
I managed to get my VB.NET service installed. Now I can't get it to do anything. Tell me how do you debug smething like this if you have to manually install the assembly to run it? the same code...
0
by: Rich Miller | last post by:
Any ideas appreciated. I have written a service application in VB (VS.Net 2003). On start, the service creates an object that instantiates a System.IO.FileSystemWatcher like so (the _watcher is...
4
by: cmgarcia17 | last post by:
I have two windows services that I've written: the first is a "Listener Service" that listens for MSMQ Message delivery. The second is a "Watcher Service" that monitors the state of the first. If...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.