Well,
I had some sleep in the meantime...
And this is what I came up with:
I had the code to write to the application event log in OnStart double.
So part of the problem is corrected. Still, the FilesSystemWatcher
seems to fire twice. Maybe I don't understand its mechanics well enough.
This is what I have in OnStart:
Me.SMSFileWatcher.Path = Path
Me.SMSFileWatcher.IncludeSubdirectories = False
Me.SMSFileWatcher.NotifyFilter = IO.NotifyFilters.LastWrite
Me.SMSFileWatcher.Filter = "freebee.jrn"
Me.SMSFileWatcher.EnableRaisingEvents = True
AddHandler SMSFileWatcher.Changed, AddressOf OnChanged
And this in OnChanged:
My.Application.Log.WriteEntry("An SMS has arrived!")
send("An SMS has arrived")
send passes the message to clients on the network...
So, everytime I open the file, change it and save it, I have the "An SMS
has arrived!" message twice in the Application event log.
Am I doing this correctly?
Thx!
Tom
Harry schreef:
"Tom Van den Brandt" <gu*******@guineapig.bewrote in message
news:uJ**************@TK2MSFTNGP06.phx.gbl...
>Hi,
I wrote a simple windows service that includes a FileSystemWatcher.
After building and installing the service (installutil) I notice that
the service executes twice. I included a write to the application
eventlog in OnStart ("service has started and is ready to watch the
filesystem") and this results in two entries in the eventlog.
Also, the handler for the FileSystemWatcher seems to be fired twice if
something happens with a file the service is watching.
I checked the machines services and in the task manager but I see only
one instance of the service running.
I'm a newbie at this, so I probably missed something obvious... Could
this be the properties of the service that were not correctly configured?
Any ideas?
Thx,
Tom
Tom, often we look at code and miss that what we are trying to accomplish is
often sabotaged by lack of observation or object/control events. Two of the
great debugging tools I have discovered are sleep and alcohol. Without
seeing your code, it is not possible to give advice. I have solved many
problems just by putting the problem to bed for a while, and come back to it
when ones' emotional state has changed. Cheers