By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,801 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Windows service with a timer

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.