473,803 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows service with a timer

I have a problem where I cannot read (all the time) a file when caught by
the FileSystemWatch er. 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 FileSystemWatch er
execute. Code below:

Private Sub FileSystemWatch er1_Created(ByV al sender As Object, ByVal e As
System.IO.FileS ystemEventArgs) Handles FileSystemWatch er1.Created
Dim poWE As New WatcherEvents
poWE.FileName = e.FullPath
poWE.Type = "Create"
maEvents.Add(po WE)
Timer1.Interval = 500
Timer1.Enabled = True

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

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

Dim poWE As WatcherEvents
......

The FileSystemWatch er1_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 2966
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************ *******@tostops pamhotmail.com> wrote in message
news:Vn******** ***********@new s04.bloor.is.ne t.cable.rogers. com...
I have a problem where I cannot read (all the time) a file when caught by
the FileSystemWatch er. 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 FileSystemWatch er
execute. Code below:

Private Sub FileSystemWatch er1_Created(ByV al sender As Object, ByVal e As
System.IO.FileS ystemEventArgs) Handles FileSystemWatch er1.Created
Dim poWE As New WatcherEvents
poWE.FileName = e.FullPath
poWE.Type = "Create"
maEvents.Add(po WE)
Timer1.Interval = 500
Timer1.Enabled = True

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

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

Dim poWE As WatcherEvents
.....

The FileSystemWatch er1_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************ *******@tostops pamhotmail.com> wrote:
I have a problem where I cannot read (all the time) a file when caught by
the FileSystemWatch er. 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 FileSystemWatch er1_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.Threadin g.Timer or the System.Timers.T imer

--
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
15696
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. Thanks Andrew
2
4714
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 log-entries I have created on stop() and start() in the eventlog works fine as well. However - the actual task is never executed. I catch the execution of the tick and in the finally-block I write to the eventlog as well. But only one entry is creates...
5
5093
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 control. The service will "sleep" for 'n' seconds using the timer control and whenever the timer_elapsed event occurs, I use the performance counter object to determine availability of few resources. Based on the availability of resources, I use the...
3
2200
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 issue is simply getting timers to work. I have a DatabaseManager.DataManagerFacade which contains a timer. Every 6 seconds it updates stock data using an online webservice. I wrote have 2 possible startup projects to make the service work. One...
3
350
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 when a service is stopped or started. What i'm trying do do now is adding a timer so after a specific period of time the service does something, in the example below writing to a text
4
5623
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 avail. Here's the code I'm using, all of which is in the main service class: Protected Overrides Sub OnStart(ByVal args() As String) AddHandler AppDomain.CurrentDomain.UnhandledException, _
2
4069
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: The MyService service on Local Computer started and then stopped. Some services stop automatically if they ahve no work to do, for example, the Perforamnce Logs and Alert service. I tried switching to a System.Threading.Timer and that didn't work...
5
606
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 thread running at any given moment. Typically, timers will have an interval of 5 to 15 minutes. Conditionally, the interval may be set to 1 second (1000 ms) before the next call to Timer.Start(). Here is the question: if the interval is one...
4
1920
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 another project that use windows form and it work. But when I implement my source code on my program that run as service on windows (I have change the code so it would work on service but I still use timer object from component), and it doesn't...
5
3312
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? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4275
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 we have to send another system
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.