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

Creating a service

Does anyone have some sample code (in VB.Net) to create a service that uses a
timer to run a function every hour?

Here's my code:
Protected Overrides Sub OnStart(ByVal args() As String)
Dim tmrState As New TimerState

' make a starting entry in the event log
EventLog.WriteEntry("FaxStatus service starting: " &
System.DateTime.Now)
' create a delegate for handling the ticking of the timer
Dim timerDelegate As New TimerCallback(AddressOf CheckStatus)
' create a timer thats waits for 1 min then ticks every hour
Dim tmrTick As New Timer(timerDelegate, tmrState, 1800000, 3600000)
' keep a handle to the timer so it can be disposed
tmrState.tmr = tmrTick
' the main thread does nothing until the timr is disposed
While Not (tmrState.tmr Is Nothing)
Thread.Sleep(0)
End While
End Sub

thx...sonny
Sep 13 '05 #1
1 1296
Sonny,

The OnStart method must return in a timely manner. Otherwise, the
service control manager will think something is wrong. What you need
to do is declare tmrTick at the class level, instantiate and start it
in the OnStart method, and let the OnStart method return immediately.

Brian

sonny wrote:
Does anyone have some sample code (in VB.Net) to create a service that uses a
timer to run a function every hour?

Here's my code:
Protected Overrides Sub OnStart(ByVal args() As String)
Dim tmrState As New TimerState

' make a starting entry in the event log
EventLog.WriteEntry("FaxStatus service starting: " &
System.DateTime.Now)
' create a delegate for handling the ticking of the timer
Dim timerDelegate As New TimerCallback(AddressOf CheckStatus)
' create a timer thats waits for 1 min then ticks every hour
Dim tmrTick As New Timer(timerDelegate, tmrState, 1800000, 3600000)
' keep a handle to the timer so it can be disposed
tmrState.tmr = tmrTick
' the main thread does nothing until the timr is disposed
While Not (tmrState.tmr Is Nothing)
Thread.Sleep(0)
End While
End Sub

thx...sonny


Sep 13 '05 #2

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

Similar topics

3
by: BobHutch | last post by:
I am trying to create a windows service using vb.net to read a sql table every half hour and copy all new records created within each half hour increment to another table. I also want to be able...
9
by: Opa | last post by:
When creating a new web service, I get the following error: Visual Studio .net cannot create or open the application. Web site 'http://localhost/WDWS' not started. The World Wide Web Publish...
2
by: Val3 | last post by:
Hi all. I need to build dll(s) and windows services using VB .NET 2005 Express. When I make File/New project the windows contain only Windows application, Windows control library, Console...
4
by: SH | last post by:
I wish to create a program (really a Windows Service) that sits and waits for a client PC to communicate with it, but I can't come up with a good method of doing so. I want to have a service...
2
by: pshvarts | last post by:
(I'm new in SOAP) I get some wsdl file (from apache service ). I tried creating SOAP client with .NET - trying to add Web Reference and get error like: "Custom tool error: Unable to import...
3
by: clsmith66 | last post by:
I hope this is just something stupid I'm missing and someone can easily point out my error. I'm trying to do a few turorials on windows services, and the couple I found so far just create an event...
16
by: tshad | last post by:
This is a little complicated to explain but I have some web services on a machine that work great. The problem is that I have run into a situation where I need to set up my program to access one...
1
by: =?Utf-8?B?cm9zczYxMw==?= | last post by:
I'm puzzled by an error message encountered while creating a Windows Service. In particular, I'm creating a second Windows Service within a Windows Service project, using Visual Studio 2005. The...
2
by: teejayem | last post by:
I am having problems creating a Windows Service using Visual Studio 2005. Code as follows:- Imports System.IO Imports System.Net.Mail
2
by: Bert Leu | last post by:
Hi I understand, that the "normal way" in creating Web Services is: Creating Web Service -- WSDL -- Creating Client Unfortunately, I have to create a Web Service (Service, not Clinet) from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.