Alvin Bruney [ASP.NET MVP]
6/24/2008 12:17:00 AM
How do you know it's not working? There maybe an exception which you won't
see since it is a service. A simple test project I created as a service is
working fine. Here is my test case.
using System;
using System.ServiceProcess;
using System.IO;
namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
FileStream fs = new FileStream(@"c:\temp\starting.txt",
FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine("i'm starting");
sw.Flush();
sw.Close();
fs.Close();
}
protected override void OnStop()
{
FileStream fs = new FileStream(@"c:\temp\stopping.txt",
FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine("i'm stopping");
sw.Flush();
sw.Close();
fs.Close();
}
private void fileSystemWatcher1_Changed(object sender,
System.IO.FileSystemEventArgs e)
{
FileStream fs = new FileStream(@"c:\temp\vapor.txt",
FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine("i'm happy");
sw.Flush();
sw.Close();
fs.Close();
}
}
}
--
Regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
-------------------------------------------------------
"Waldy" <someone@microsoft.com> wrote in message
news:OewaISU1IHA.3884@TK2MSFTNGP05.phx.gbl...
> Hi there,
> I cannot get the FileSystemWatcher to work. I want to
> monitor a directory for when files are copied into it. I have set the
> Filter property to *.* and the NotifyFilter property to CreationTime.
> However, the Created event never gets raised. I'm running it from a
> system service if that makes any difference.
>