473,408 Members | 2,832 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,408 software developers and data experts.

Windows service with a timer

I have a problem where I cannot read (all the time) a file when caught by
the FileSystemWatcher. What I have done to get past this is create an array
of events (when I receive one I add it to the list). I then enable a timer
which will attempt to process the first one in the list.

The timer code is never executed. There is a handles clause on the timer
and using the debugger I have watched the code for the FileSystemWatcher
execute. Code below:

Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created
Dim poWE As New WatcherEvents
poWE.FileName = e.FullPath
poWE.Type = "Create"
maEvents.Add(poWE)
Timer1.Interval = 500
Timer1.Enabled = True

LogChange(e.FullPath, "Creating request for ", 102)
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
LogChange("", "Enter timer routine ", 997)
If maEvents.Count = 0 Then Exit Sub

Dim poWE As WatcherEvents
......

The FileSystemWatcher1_Created executes and the log event happens. The
timer1_tick does not execute. Even when not debugging I should see the
event log at the beginning of the code for that routine but there is
nothing.

Lloyd Sheen
Jul 21 '05 #1
3 2937
For anyone trying this, it seems that the timer which you can drag to the
service designer does not work. I guess it has to be hosted by a form.
Once again the IDE should stop the developer from doing this if it will not
work.

Lloyd Sheen

"Lloyd Sheen" <sq*******************@tostopspamhotmail.com> wrote in message
news:Vn*******************@news04.bloor.is.net.cab le.rogers.com...
I have a problem where I cannot read (all the time) a file when caught by
the FileSystemWatcher. What I have done to get past this is create an array of events (when I receive one I add it to the list). I then enable a timer which will attempt to process the first one in the list.

The timer code is never executed. There is a handles clause on the timer
and using the debugger I have watched the code for the FileSystemWatcher
execute. Code below:

Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As
System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created
Dim poWE As New WatcherEvents
poWE.FileName = e.FullPath
poWE.Type = "Create"
maEvents.Add(poWE)
Timer1.Interval = 500
Timer1.Enabled = True

LogChange(e.FullPath, "Creating request for ", 102)
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
LogChange("", "Enter timer routine ", 997)
If maEvents.Count = 0 Then Exit Sub

Dim poWE As WatcherEvents
.....

The FileSystemWatcher1_Created executes and the log event happens. The
timer1_tick does not execute. Even when not debugging I should see the
event log at the beginning of the code for that routine but there is
nothing.

Lloyd Sheen

Jul 21 '05 #2
On 2004-01-28, Lloyd Sheen <sq*******************@tostopspamhotmail.com> wrote:
I have a problem where I cannot read (all the time) a file when caught by
the FileSystemWatcher. What I have done to get past this is create an array
of events (when I receive one I add it to the list). I then enable a timer
which will attempt to process the first one in the list.

<snip>
The FileSystemWatcher1_Created executes and the log event happens. The
timer1_tick does not execute. Even when not debugging I should see the
event log at the beginning of the code for that routine but there is
nothing.

Lloyd Sheen


Lloyd,

You can't use the windows forms timer in a service. You need to use
eiter the System.Threading.Timer or the System.Timers.Timer

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
A clash of doctrine is not a disaster -- it is an opportunity.
Jul 21 '05 #3
Rob
Use the timer in the components tool box, not the windows forms timer. This timer has an elapsed event which is the same as the form timer tick event. I had this same problem when I first made services with the tick not firing, and then I stumbled upon the components timer and this fixed it

Jul 21 '05 #4

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

Similar topics

2
by: andrewcw | last post by:
I am trying to do a windows service with C#. I am using as a base the VB.NET article in VS, but I thing the WITHEVENTS timer notation is a delegate. Can anyone provide sample code & anh hints. ...
2
by: Jesper Stocholm | last post by:
I have created a simple service which just copies a fil to a new file with a new name on certain intervals (the service implements a timer). I have no problems installing the service and the...
5
by: Dhilip Kumar | last post by:
Hi all, I have developed a windows service using the windows service project template in VS.NET. I have used three controls in the service, a timer, performance counter and a message queue...
3
by: Nathan Kovac | last post by:
I have a feeling I am missing something simple, but I just can't find it. Perhaps someone can give me a lead on where to look. I will describe the issue then post my code to the web service. My...
3
by: Yves Royer | last post by:
Hi all, I have a little question about Windows Services. For my app i need 3 different Windows Services, each with its own functionality. I'm trying to make a test service to see what happens...
4
by: Groundskeeper | last post by:
I can't seem to get a custom UnhandledException handler working for a Windows Service I'm writing in VB.NET. I've read the MSDN and tried various different placements of the AddHandler call, to no...
2
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: ...
5
by: Tom | last post by:
Using multiple System.Timers.Timer objects in a Windows Service for performing multi-thread activities in a periodic fashion. Timers are AutoReset=false, to only have a single timer execution...
4
by: Lemune | last post by:
Hello everyone. I'm using vb 2005. I'm creating program that run as service on windows. And in my program I need to use timer, so I'm using timer object from component. I try my source code on...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.