|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Need help on windows service and timerHello 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 another project that use windows form and it work. But when I implement my source code on my program that run as service on windows (I have change the code so it would work on service but I still use timer object from component), and it doesn't work. I'm suspecting that the problem is because I use timer object from component. I need some suggestion here. Thanks in advances. Lemune wrote:
> I'm using vb 2005. I'm creating program that run as service on windows. System.Threading.Timer?> And in my program I need to use timer, so I'm using timer object from > component. System.Timers.Timer? System.Windows.Forms.Timer? > But when I implement my source code on my program that run as service As ever, /please/ define "doesn't work".> on windows (I have change the code so it would work on service but I > still use timer object from component), and it doesn't work. The Service doesn't start [properly]? The Timer never seems to fire? The Timer fires initially, then "gives up" after a while? > I'm suspecting that the problem is because I use timer object System.Timers.Timer is the one you want.> from component. Better still, only use this Timer to "side-step" the OnStart method's call/return sequence (allowing Windows to tell that your service has started properly), then kick off your main processing loop and, within that, use System.Threading.Thread.Sleep() /instead/ of a Timer, something like: Imports System.Threading Private bRunService as Boolean = True Private bStopped as Boolean = False Sub OnStart() tmrStarter.Start() End Sub Sub OnStop() ' If you have a long-running process that /must/ finish cleanly, ' don't allow OnStop to return until you've cleaned up. ' Windows will kill your Service process as soon as OnStop returns. bRunService = False Do While Not bStopped Thread.Sleep( 1000 ) Loop End Sub Sub tmrStarter_Elapsed( ... ) _ Handles tmrStarter.Elapsed tmrStarter.Stop() Me.Run() End Sub Sub Run() Do While bRunService DoSomethingUseful() Thread.Sleep( 100 ) Loop bStopped = True End Sub HTH, Phill W. Thank you for your advice.
>System.Threading.Timer? I think I use System.Windows.Forms.Timer. :))>System.Timers.Timer? >System.Windows.Forms.Timer? > The Timer never seems to fire? My service start just fine, but it seem that the timer never fire.I will try using System.Threading.Timer. And I will inform you again. Thank you Phill W.
I have use your suggestion. And my service work. Know i use System.Timers.Timer and System.Threading. Once again thanks Phill Thank you Phill W.
I have use your suggestion. And my service work. Now i use System.Timers.Timer and System.Threading. Once again thanks Phill
Multithread Revisted
ulong vs UInt64 Live multi-user debugging? Help! Can I use an asterisk in the "Imports" statement? Accessing existing Excel instance CheckedListbox backcolor question File.Exists not working. Transferring data between datatables and between datareader and datatable Confused About Dispose and Finalize in VS.Net How to use DataGridComboColumnStyle |
|||||||||||||||||||||||