473,498 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Service executes twice

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
Nov 6 '07 #1
4 2352
"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
Nov 7 '07 #2
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

Nov 7 '07 #3
Tom Van den Brandt wrote:
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
Did you declare SMSFileWatcher "WithEvents"?

If so, VB will have /automatically/ wired-up the OnChanged Event for you
and your AddHandler statement will simply add /another/ handler to that
event; it won't "undo" or "replace" an existing one.
And this in OnChanged:
I'm not entirely sure why but, whenever I've used the FileSystemWatcher,
I've had to allow for multiple events in rapid succession - you seem to
get duplicate "change" events even if the file only changes once.

HTH,
Phill W.
Nov 7 '07 #4
Phill W. schreef:
Tom Van den Brandt wrote:
>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

Did you declare SMSFileWatcher "WithEvents"?
Even when I comment out the Addhandler line and the EnableRaisingEvents
line (and put the code in OnChanged in
Private Sub SMSFileWatcher_Changed
The code is still executed twice.

I'm thinking that for some reason the filewatcher is firing the event
twice...

Thx for your suggestions!
>
If so, VB will have /automatically/ wired-up the OnChanged Event for you
and your AddHandler statement will simply add /another/ handler to that
event; it won't "undo" or "replace" an existing one.
>And this in OnChanged:

I'm not entirely sure why but, whenever I've used the FileSystemWatcher,
I've had to allow for multiple events in rapid succession - you seem to
get duplicate "change" events even if the file only changes once.

HTH,
Phill W.
Nov 7 '07 #5

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

Similar topics

10
3155
by: Manny | last post by:
I have a web form "Page1.asp" and it reads data from a database, does some calculations, and displays the records in pages. Works fine. I have a button that displays on the page, defined as...
2
13156
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using...
3
2523
by: erdem | last post by:
hi, i have a problem with asp.net when i was debugging i put breakpoint to pageload event and then i discovered that page is loaded once (explorer shows full page correctly but continues...
5
2351
by: Bob | last post by:
I've got a .NET Framework V1.1 web service running on a Windows 2003 Server that has 2 web methods that are called from a web application on the same server. One is a fire-and-forget method that...
0
1126
by: rajendra.mishra | last post by:
Hi... I have a frame(Report.htm) which has two aspx pages one for header(header.aspx) and the other for displaying reports(Report.aspx). when Report.htm is called Report.aspx executes twice. I...
4
1967
by: Ashley Bryant | last post by:
I've created a Windows Service in vb.net that is set up to run automatically, but it never starts during system startup. I can start it manually, but I need the service to start without any user...
4
2841
by: David C | last post by:
I spent the last four hours trying to figure out why Page_Load would execute twice. Even stranger was that everything within if (! IsPostBack){....} executed twice as well. There is no rhyme or...
6
3339
by: alho | last post by:
The web service is called by a program running on pocket pc. When to call the web service, the first call is still ok, but for the second or later calls, it will throw "403 Forbidden" WebException....
0
808
by: inlovewithmusic | last post by:
Hi , Ok, first of all please don't run away because of the long paragraph I am about to write, its just that there's no way for me to write the problem down in a few lines :)... So I have...
0
7126
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
7005
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
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7210
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...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.