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

Windows service timer problem


Hello,
I'm having a go at writing my first Windows Service in VB.NET and I'm
having a problem. I have it installed ok and started the service
sucessfully, I can stop it, and restart it fine, the problem is it
doesn't appear to be running any of my code whatsoever.

I dropped a Timer Control on the designer, set it to disabled with an
interval of 5000, went to the code window and on the OnStart Event,
typed in:
Timer1.Enabled=True

But the .Tick event never fires at all. I've tested this out by
putting a MsgBox in the Onstart event, and sure enough the service
stops right away becuase of that. I then cut it out of there, and put
it as the first thing in Timer1's .Tick event, the service runs
without stopping itself...its not hitting the Msgbox

I even tried another approach, creating a new thread in the OnStart
event, and Starting the thread, but again, the thread never starts.

It will run anything I put in the Onstart event, unless it involves
running any other Subs or Functions.

Any Help?

Scott

Nov 20 '05 #1
3 9483

I'm still stuck, someone must have written a windows Service in VB.NET
to get back to basics, I made this...

Protected Overrides Sub OnStart(ByVal args() As String)
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As_
System.EventArgs) Handles Timer1.Tick
'this event is never fired
End Sub

(created as a window service)
It compiles, installs and I can start the service, but Timer1_tick is
never fired. I put the Timer1 onto the designer window rather than
create one in code.
Scott

Nov 20 '05 #2
On Fri, 04 Jun 2004 15:31:41 GMT, Scott H wrote:
I dropped a Timer Control on the designer, set it to disabled with an
Which timer control? There are several available. The Windows Forms Timer
is probably not appropriate. Try the System.Timers.Timer
it as the first thing in Timer1's .Tick event, the service runs
without stopping itself...its not hitting the Msgbox


Is the service set up to allow interaction with the desktop? If not, the
msgbox code may be executing but you just may not see it.

To debug, try setting the timer interval to something larger like 10
seconds then start the service and then attach the debugger to it and put a
breakpoint inside the timer tick code. That should show if it is hitting
the timer code or not.

--
Chris

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 20 '05 #3
You have to create the timer in code;

Private mvTimer As New System.Timers.Timer(5000)

Protected Overrides Sub OnStart(ByVal args() As String)
AddHandler mvTimer.Elapsed, AddressOf mvTimer_Elapsed
mvTimer.Enabled = True
' or mvTimer.Start (not sure of the exact difference yet...)
End Sub

Private Sub mvTimer_Elapsed(ByVal pSender As Object, ByVal pArgs As
System.Timers.ElapsedEventArgs)
'this event had better fire!!
MessageBox.Show("I fired!!", "Yay!", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Sub

(add mvTimer.Enabled = False (or mvTimer.Stop) and RemoveHandler... to Sub
OnStop for completeness)
_____________________________
The Grim Reaper

"Scott H" <x@y.com> wrote in message
news:h9********************************@4ax.com...

I'm still stuck, someone must have written a windows Service in VB.NET
to get back to basics, I made this...

Protected Overrides Sub OnStart(ByVal args() As String)
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As_
System.EventArgs) Handles Timer1.Tick
'this event is never fired
End Sub

(created as a window service)
It compiles, installs and I can start the service, but Timer1_tick is
never fired. I put the Timer1 onto the designer window rather than
create one in code.
Scott

Nov 20 '05 #4

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

Similar topics

3
by: ray | last post by:
Hi, I just wrote a windows service application to call a function of another object periodically. I used System.Server.Timer and I found that it works fine within the first 2 hours but the...
2
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. ...
2
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...
5
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...
7
by: Doug Stiers | last post by:
I have a VB app that I'm installing as a Windows Service. I want a subroutine in the app to run every 30 minutes during business hours. How do I do this in VB? I set the startup type as automatic...
2
by: Trevor | last post by:
Argh! This problem is driving me nuts! Can you help? In November of 2003, I installed a web service on Windows Server 2003 built in VB.NET for v1.1.4322 of the framework. It contains a timer...
5
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...
4
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...
8
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location...
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
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?
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...

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.