473,382 Members | 1,784 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,382 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 1298
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
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.