473,770 Members | 4,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to loop in Windows Service?

I have a need to write a Windows Service application in VB.Net that
needs to continuously do some processing, wait ten minutes, then
repeat. What is a good approach to coding this type of thing?
Basically, I want something like:

While True
-- do some processing

-- sleep 10 minutes

End While

I can't put a loop like this in the OnStart event handler, because then
the service never finishes starting in MMC. I thought of using a Timer
instead of a Sleep, but I don't want the processing to occur every 10
minutes when the Timer.Elapsed event fires - I want a 10 minute pause
after the processing completes.

Has anyone implemented a similar application, or have any suggestions
as how this can best be done?

Thanks in advance for any replies.

Nov 23 '05 #1
5 10592
try puting a timer... that fires only once... lets say... on start
event.. fires.. loads everything thats needs to be loaded... 10 seconds
later, your loop is started.. and timer i disabled... now you can loop
your way... after onstart event has finished.....

add second timer.. or do custom logic and use the sam... that will will
start 10 minute count down after your procesing is finished.....

Nov 23 '05 #2
Kick off your processing in a thread. Start the thread in the OnStart.
The thread can then loop as you wanted.

Nov 23 '05 #3
<eb**@pipeline. com> schrieb:
I have a need to write a Windows Service application in VB.Net that
needs to continuously do some processing, wait ten minutes, then
repeat. What is a good approach to coding this type of thing?
Basically, I want something like:

While True
-- do some processing

-- sleep 10 minutes

End While

I can't put a loop like this in the OnStart event handler, because then
the service never finishes starting in MMC. I thought of using a Timer
instead of a Sleep, but I don't want the processing to occur every 10
minutes when the Timer.Elapsed event fires - I want a 10 minute pause
after the processing completes.


Start processing in a new thread (see 'Thread' class and 'ThreadStart'
delegate). Then you can use 'System.Threadi ng.Thread.Sleep ' to block the
thread for a certain period of time.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #4
eb65,
In addition to the other comments, I normally use either
System.Threadin g.Timer or System.Timers.T imer and handle the respective
callback or Elapsed event.

If you us System.Timers.T imer, be certain to review the following KB article
first:
BUG: The Elapsed event of the System.Timers.T imer class is not raised in a
Windows service
http://support.microsoft.com/default...b;en-us;842793

For info on the 3 timers (the above two & System.Windows. Forms.Timer) see:

Comparing the Timer Classes in the .NET Framework Class Library
http://msdn.microsoft.com/msdnmag/is...T/default.aspx
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
<eb**@pipeline. com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
|I have a need to write a Windows Service application in VB.Net that
| needs to continuously do some processing, wait ten minutes, then
| repeat. What is a good approach to coding this type of thing?
| Basically, I want something like:
|
| While True
| -- do some processing
|
| -- sleep 10 minutes
|
| End While
|
| I can't put a loop like this in the OnStart event handler, because then
| the service never finishes starting in MMC. I thought of using a Timer
| instead of a Sleep, but I don't want the processing to occur every 10
| minutes when the Timer.Elapsed event fires - I want a 10 minute pause
| after the processing completes.
|
| Has anyone implemented a similar application, or have any suggestions
| as how this can best be done?
|
| Thanks in advance for any replies.
|
Nov 23 '05 #5
Chris Dunaway wrote:
Kick off your processing in a thread. Start the thread in the OnStart.
The thread can then loop as you wanted.


this is good to know.... cose i'm too still learining... especialy to
make windows service.... my works for now...now i'll modify it with
suggestions made here :-)

Nov 23 '05 #6

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

Similar topics

8
2032
by: Fabio Papa | last post by:
I am trying to write a windows service that sends emails to clients at specific times based on information in a sql db. Since this is done for multiple cities, I start a thread for each city and continue the processing from each thread. My service starts fine (gives me no errors, etc), but it doesn't seem to start the new threads. I am new to windows services, so I don't know if I'm doing something wrong. Should I maybe be doing this...
3
9431
by: James Dixon | last post by:
I have created a windows service in C#, .net framework 1.1 The service makes a web request using the mshtml.HTMLDocument.CreateDocumentFromURL() function Because this is not using Windows.Forms, I can't use the Application.DoEvents() function while the request is completing. Is there an equivilent function (call the CreateDocumentFromURL from a seperate thread and spin it until Document.readyState != "complete"?
4
8632
by: Graham Siener | last post by:
Hi All, I have a real confusion situation on my hands. I've written a windows service in c# that basically does archiving of data from one database to another. Along the way it parses one field which is a large xml document into many children fields. This service uses COM+ components also written in c#, but the service is triggered by a windows event. My problem is this: The service works fine when archiving a small number of...
1
4475
by: benmorganpowell | last post by:
I have a small windows service which connects to a POP3 server at defined intervals, scans the available messages, extracts the required information and inserts the data into a SQL database. I am assuming that this is not an uncommon piece of software. I want to get an architecture that conforms as closely as possible with the recommendations from Microsoft on developing Windows Services, but to be honest I have found difficultly in...
2
11162
by: Ankit Aneja | last post by:
I am making windows service using Microsoft visual studio.Net in C# service name is clamservice problem is that when i start the service it through control pannel->Administrative tools->services it shows "starting" and never shows "started" it goes somewhere in loop i am doing some logical mistake i want to create service supporting multiple clients using threading pls help me code:
6
8119
by: D | last post by:
I have a simple file server utility that I wish to configure as a Windows service - using the examples of the Python Win32 book, I configured a class for the service, along with the main class functions __init__, SvcStop, and SvcDoRun (which contains my server code). After registering the service, I am able to start it with no problems. However, it never stops correctly (net stop returns "service could not be stopped") and service is left...
1
1353
by: CraigMuckleston | last post by:
I have built a windows service that should check whether a page can be returned from a site (from various servers). If not, it logs to the Application Error log. My trouble is this. It runs once, but doesn't seem to loop at all, ie, I only get the 1 round of warning messages (it also sends me a net message, but that will be removed eventually). My code for the whole service is below: Imports System Imports System.IO Imports System.Net...
28
7379
by: | last post by:
I have a multi threaded windows form application that runs great after calling Application.Run(). Application.Run is required for a COM component I a using in the app (required for message loop). I have created a windows service from VStudio 2005 template. What is the windows service replacement for Application.Run()?
10
7544
by: archana | last post by:
Hi all, I am having one windows service which is updating to database. On 'Onstop i want to wait till current updation complete. How will i do this? Because if i write some lengthy code on onstop it fails to stop and status remain 'stopping' Later i can't do anything on that service even i can't uninstall that service.
5
3307
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
9602
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
10237
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9882
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...
1
7431
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
6690
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();...
1
3987
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
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
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.