Hello everyone,
I have made a service that starts timers when it starts. I have
another windows form application that stops and starts the service. Do
I need to deal with any started timers when the service stops? Being
new at this service stuff, I don't know if it holds state or memory
and I need to stop all active timers or if the magical gc will come
along and help out.
Thanks, I hope that makes sense.
Have a great day,
Ryan 10 1942
Ryan wrote:
Hello everyone,
I have made a service that starts timers when it starts. I have
another windows form application that stops and starts the service. Do
I need to deal with any started timers when the service stops? Being
new at this service stuff, I don't know if it holds state or memory
and I need to stop all active timers or if the magical gc will come
along and help out.
Thanks, I hope that makes sense.
In your case here, if the timers were started on the parent thread, the
tread the service started up on, the the timers are going to be killed
when the service stops. However, if the timer was instantiated on a
spawned child thread and you don't kill the thread even though you have
stopped the service, then the child thread and the timer will still be
running.
The magical GC will kill the timer while the service is running if
you're not careful, GC.Keepalive will prevent that.
The proper way to write a timed execution in a .Net service is to use
threads on a timed basis, using the Tread.Sleep in a While True Loop.
I have NEVER heard that.... I was always told by people and MS people to use
the Threading.Timer for services and to always avoid while loops for this
"DArnold" <DA*****@DArnol d.comwrote in message
news:eR******** *****@TK2MSFTNG P06.phx.gbl...
Ryan wrote:
>Hello everyone,
I have made a service that starts timers when it starts. I have another windows form application that stops and starts the service. Do I need to deal with any started timers when the service stops? Being new at this service stuff, I don't know if it holds state or memory and I need to stop all active timers or if the magical gc will come along and help out.
Thanks, I hope that makes sense.
In your case here, if the timers were started on the parent thread, the
tread the service started up on, the the timers are going to be killed
when the service stops. However, if the timer was instantiated on a
spawned child thread and you don't kill the thread even though you have
stopped the service, then the child thread and the timer will still be
running.
The magical GC will kill the timer while the service is running if you're
not careful, GC.Keepalive will prevent that.
The proper way to write a timed execution in a .Net service is to use
threads on a timed basis, using the Tread.Sleep in a While True Loop.
"Smokey Grindle" <no****@nospam. comwrote in message
news:%2******** *********@TK2MS FTNGP02.phx.gbl ...
>I have NEVER heard that.... I was always told by people and MS people to use the Threading.Timer for services and to always avoid while loops for this
What MS people? When I first started writing .Net services on VS 2003 using
the Framework 1.1, a guy I worked for questioned me about why I was using a
While True loop. I told him it came right out of the VS Help for threading.
Then he came back with an article about the Whlie True loop was the
preferred method using Thread.Sleep in a .NET Service. I have been looking
for that link, but I cannot find it.
When I am writing a .NET Service or Console application, then I am going to
spawn a child thread using a delegate with a While True loop, as the worker
thread or threads. The only Timer I will use is to check thread state.
public class StartThread()
{
try
{
while true
{
do something
Thread.Sleep(ti metowait)
}
}
Catch ThreadException as tex //if it hits the Catch, then it's coming
out of the loop
{
do something
}
}
"Smokey Grindle" <no****@nospam. comwrote in message
news:%2******** *********@TK2MS FTNGP02.phx.gbl ...
>I have NEVER heard that.... I was always told by people and MS people to use the Threading.Timer for services and to always avoid while loops for this
"DArnold" <DA*****@DArnol d.comwrote in message
news:eR******** *****@TK2MSFTNG P06.phx.gbl...
>Ryan wrote:
>>Hello everyone,
I have made a service that starts timers when it starts. I have another windows form application that stops and starts the service. Do I need to deal with any started timers when the service stops? Being new at this service stuff, I don't know if it holds state or memory and I need to stop all active timers or if the magical gc will come along and help out.
Thanks, I hope that makes sense. In your case here, if the timers were started on the parent thread, the tread the service started up on, the the timers are going to be killed when the service stops. However, if the timer was instantiated on a spawned child thread and you don't kill the thread even though you have stopped the service, then the child thread and the timer will still be running.
The magical GC will kill the timer while the service is running if you're not careful, GC.Keepalive will prevent that.
The proper way to write a timed execution in a .Net service is to use threads on a timed basis, using the Tread.Sleep in a While True Loop.
have a look at http://www.codeproject.com/useritems...sp?msg=2070389
I concur with smokey about this
i also remember that the way to go in services is to use a threading timer
i have a few services out there running with a threading timer without anny
problems
michel posseth
"Smokey Grindle" <no****@nospam. comschreef in bericht
news:%2******** *********@TK2MS FTNGP02.phx.gbl ...
>I have NEVER heard that.... I was always told by people and MS people to use the Threading.Timer for services and to always avoid while loops for this
"DArnold" <DA*****@DArnol d.comwrote in message
news:eR******** *****@TK2MSFTNG P06.phx.gbl...
>Ryan wrote:
>>Hello everyone,
I have made a service that starts timers when it starts. I have another windows form application that stops and starts the service. Do I need to deal with any started timers when the service stops? Being new at this service stuff, I don't know if it holds state or memory and I need to stop all active timers or if the magical gc will come along and help out.
Thanks, I hope that makes sense. In your case here, if the timers were started on the parent thread, the tread the service started up on, the the timers are going to be killed when the service stops. However, if the timer was instantiated on a spawned child thread and you don't kill the thread even though you have stopped the service, then the child thread and the timer will still be running.
The magical GC will kill the timer while the service is running if you're not careful, GC.Keepalive will prevent that.
The proper way to write a timed execution in a .Net service is to use threads on a timed basis, using the Tread.Sleep in a While True Loop.
"Michel Posseth [MCP]" <MS**@posseth.c omwrote in message
news:OT******** ******@TK2MSFTN GP04.phx.gbl...
>I concur with smokey about this
i also remember that the way to go in services is to use a threading timer
i have a few services out there running with a threading timer without
anny problems
What? You think I am making this up?
I concur with what the VS 2003 Help talked about in its examples of using a
While True loop with Thread.Sleep. I also concur with the article that was
placed before me about what should be done in a timed execution of a thread
in a .NET Service application, which was to use a While True loop and
Thread.sleep. But I can't find that article, which was presented to me back
in 2004. I recall it was a MSDN article.
I have written a few .Net service and Console applications myself, and the
method I use for Treading using a sleep/wait period is what I talked about,
without any problems. The only Timer I use is to check Thread or Threads
state on a periodic basis.
..Net MCP 2003 vantage as well here and maybe MCPD 2005 vantage if I have the
energy to do it, as I am getting too old and may not go after it. But I will
go through the MS Press training kit books anyway.
One other thing here, MS MCTS 70-536 book has an entire chapter on
Threading. Throughout the entire chapter 7 with its examples of execution of
a thread on a timed basis, it's using a For or While loop with Tread.Sleep.
There is only one page that talks about using a System.Thread.T imer, which I
cannot say not to use a Timer. But the preferred way it seems, at least in
the examples of Threading in the book, are using a loop with Thread.Sleep.
every MS person I ever talked to said use threading.timer s... I am talking
about in person here at tech demos and such... they always shyed away from
using while loops and sleeping
"Mr. Arnold" <MR. Ar****@Arnold.c omwrote in message
news:Ol******** ******@TK2MSFTN GP03.phx.gbl...
One other thing here, MS MCTS 70-536 book has an entire chapter on
Threading. Throughout the entire chapter 7 with its examples of execution
of a thread on a timed basis, it's using a For or While loop with
Tread.Sleep. There is only one page that talks about using a
System.Thread.T imer, which I cannot say not to use a Timer. But the
preferred way it seems, at least in the examples of Threading in the book,
are using a loop with Thread.Sleep.
"Smokey Grindle" <no****@nospam. comwrote in message
news:OT******** ******@TK2MSFTN GP02.phx.gbl...
every MS person I ever talked to said use threading.timer s... I am talking
about in person here at tech demos and such... they always shyed away from
using while loops and sleeping
That's them and I don't agree with them is the bottom line. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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. Thanks Andrew
|
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 log-entries I have
created on stop() and start() in the eventlog works fine as well.
However - the actual task is never executed. I catch the execution of
the tick and in the finally-block I write to the eventlog as well. But
only one entry is creates...
|
by: J. Hill |
last post by:
I have a Windows Service with a timer but the .Tick event is not being fired/called.
Don't know what code to include...I enabled and started the timer...I have the exact same code in a Windows form and it works fine, but in the service: nothing.
....
this.components = new System.ComponentModel.Container();
this.tmrTimer = new System.Windows.Forms.Timer(this.components);
//
// tmrTimer
//
|
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 control. The service will "sleep"
for 'n' seconds using the timer control and whenever the timer_elapsed event
occurs, I use the performance counter object to determine availability of
few resources. Based on the availability of resources, I use the...
|
by: Nathan Kovac |
last post by:
I have a feeling I am missing something simple, but I just can't find it.
Perhaps someone can give me a lead on where to look. I will describe the
issue then post my code to the web service. My issue is simply getting
timers to work. I have a DatabaseManager.DataManagerFacade which contains a
timer. Every 6 seconds it updates stock data using an online webservice. I
wrote have 2 possible startup projects to make the service work. One...
| |
by: Yves Royer |
last post by:
Hi all,
I have a little question about Windows Services.
For my app i need 3 different Windows Services, each with its own
functionality. I'm trying to make a test service to see what happens when a
service is stopped or started.
What i'm trying do do now is adding a timer so after a specific period of
time the service does something, in the example below writing to a text
|
by: Groundskeeper |
last post by:
I can't seem to get a custom UnhandledException handler working for a
Windows Service I'm writing in VB.NET. I've read the MSDN and tried
various different placements of the AddHandler call, to no avail.
Here's the code I'm using, all of which is in the main service class:
Protected Overrides Sub OnStart(ByVal args() As String)
AddHandler AppDomain.CurrentDomain.UnhandledException, _
|
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 thread running at any
given moment.
Typically, timers will have an interval of 5 to 15 minutes. Conditionally,
the interval may be set to 1 second (1000 ms) before the next call to
Timer.Start().
Here is the question: if the interval is one...
|
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?
Why do I need to set a property within my code to the service name?
Are all these required or am I just doing this for consistency purposes?
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |