473,386 Members | 1,753 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,386 software developers and data experts.

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 10551
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.Threading.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.Threading.Timer or System.Timers.Timer and handle the respective
callback or Elapsed event.

If you us System.Timers.Timer, be certain to review the following KB article
first:
BUG: The Elapsed event of the System.Timers.Timer 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.googlegr oups.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
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...
3
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...
4
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...
1
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...
2
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...
6
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...
1
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...
28
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). ...
10
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...

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.