473,385 Members | 2,004 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 (Restart itself)

Hello,

I have a windows service. I want to restart it after every 24 hour. Is it
possible to restart the service programmatically(from the service itself)
using the sercvice controller object? Or should i chose some other approach?

Any ideas?

Thanx for all help.
- Iceman
Nov 20 '05 #1
14 25055
If you don't want to get complicated, use the NT SC.EXE (service controller)
in command line mode to start your service. Set the command line for it in
the system scheduler.

-Rob Teixeira [MVP]

"iceman" <ic****@hotmail.com> wrote in message
news:eF**************@TK2MSFTNGP11.phx.gbl...
Hello,

I have a windows service. I want to restart it after every 24 hour. Is it
possible to restart the service programmatically(from the service itself)
using the sercvice controller object? Or should i chose some other approach?
Any ideas?

Thanx for all help.
- Iceman

Nov 20 '05 #2
Although you could user a ServiceController to stop your service, once it is
stopped it won't be able to start itself.

By far the easiest way is to have a batch file with:

net stop <servicename>
net start <servicename>

and schedule that to run once a day at the desired time of day.
"iceman" <ic****@hotmail.com> wrote in message
news:eF**************@TK2MSFTNGP11.phx.gbl...
Hello,

I have a windows service. I want to restart it after every 24 hour. Is it
possible to restart the service programmatically(from the service itself)
using the sercvice controller object? Or should i chose some other approach?
Any ideas?

Thanx for all help.
- Iceman

Nov 20 '05 #3
Cor
Hi Stephany,

Where did you be?

Cor
Nov 20 '05 #4
Been really busy the last few weeks - just finished a major overhaul of a
fairly large project.

"Cor" <no*@non.com> wrote in message
news:O2**************@TK2MSFTNGP10.phx.gbl...
Hi Stephany,

Where did you be?

Cor

Nov 20 '05 #5
Could i solve this issue by starting a new process(a bat file which contains
comands to stop and then start the service) from the windows service?
Is it possible?

(I have actually no control over the system schedular.)

Thanx
-Iceman

"Stephany Young" <stephany@localhost> wrote in message
news:uL**************@TK2MSFTNGP09.phx.gbl...
Although you could user a ServiceController to stop your service, once it is stopped it won't be able to start itself.

By far the easiest way is to have a batch file with:

net stop <servicename>
net start <servicename>

and schedule that to run once a day at the desired time of day.
"iceman" <ic****@hotmail.com> wrote in message
news:eF**************@TK2MSFTNGP11.phx.gbl...
Hello,

I have a windows service. I want to restart it after every 24 hour. Is it possible to restart the service programmatically(from the service itself) using the sercvice controller object? Or should i chose some other

approach?

Any ideas?

Thanx for all help.
- Iceman


Nov 20 '05 #6
Could i solve this issue by starting a new process(a bat file which contains
comands to stop and then start the service) from the windows service?
Is it possible?

(I have actually no control over the system schedular.)

Thanx
-Iceman

"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:eg**************@TK2MSFTNGP11.phx.gbl...
If you don't want to get complicated, use the NT SC.EXE (service controller) in command line mode to start your service. Set the command line for it in
the system scheduler.

-Rob Teixeira [MVP]

"iceman" <ic****@hotmail.com> wrote in message
news:eF**************@TK2MSFTNGP11.phx.gbl...
Hello,

I have a windows service. I want to restart it after every 24 hour. Is it possible to restart the service programmatically(from the service itself) using the sercvice controller object? Or should i chose some other

approach?

Any ideas?

Thanx for all help.
- Iceman


Nov 20 '05 #7
Hi Iceman,

Why do you want to do that?
Did you get memory leaks so that you work around in this way?

If it was a COM+ service, I think you use COM+ administration library to
do the stuff.
Automating COM+ Administration
http://msdn.microsoft.com/library/de...us/cossdk/htm/
pgdeployingapplications_5cmf.asp

For a regular service, I think you need to use a watchdog service to do
it.(similar with the task schedule).
But you should rather fix your memory leaks.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #8
Hi Peter,

The services I am talking about is completely developed by managed code. The
reason i awant to restart the services for example each 24 hours is because
"some times" one of those services stops to do the task they was made for.
The service status is still running in the serivce control manager. When the
service is restarted then everything works fine... I am not sure why this
happens.... I have try and catch blocks "everywhere" in the code. Database
connections are Creted / Opened / Closed / Distroyed .etc.

Any ideas?

Thanx for you help and time.

Best regards
-Iceman
"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:um**************@cpmsftngxa07.phx.gbl...
Hi Iceman,

Why do you want to do that?
Did you get memory leaks so that you work around in this way?

If it was a COM+ service, I think you use COM+ administration library to
do the stuff.
Automating COM+ Administration
http://msdn.microsoft.com/library/de...us/cossdk/htm/ pgdeployingapplications_5cmf.asp

For a regular service, I think you need to use a watchdog service to do
it.(similar with the task schedule).
But you should rather fix your memory leaks.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #9
Hi Iceman,

I think you may try to do the task in a seperate thread in which it will
signal an event to tell the service process that it was alive. If the
signal doesn't produce in a fixed period, there should be something wrong
with the working thread, you may try to Abort the thread and restart it
again.

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #10
Hi Peter,

I am using multiple threads in the windows service. Some thread works fine
and some doesnt. Maybe there is a good idea to abort the thread an restart
it. I am actually confused why some of the threads "die". Is it because it
occurs unexpected errors? Could it be something else? Any ideas?

Thanx
-Iceman
"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:en**************@cpmsftngxa07.phx.gbl...
Hi Iceman,

I think you may try to do the task in a seperate thread in which it will
signal an event to tell the service process that it was alive. If the
signal doesn't produce in a fixed period, there should be something wrong
with the working thread, you may try to Abort the thread and restart it
again.

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #11
Hi Iceman,

Usually it may be caused by waiting for an sychronized object.
Since in multiple thread programming, you must use the sychronized
mechanism to make the threads works properly.

So you may try to check if the "dead" thread is waiting for an synchronized
object, or it attempted to access a resouce which is occupied by another
one thread or process.

Or you are execute an time-consuming procudure(e.g. query in the database)?

Can you tell me what are the "die" threads doing?

You may try to set the timeout value when you wait for a resource, so that
the thread will not wait infinitely.

If you have any concern on this issue,please post here.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #12
Hi again Peter,

The dieing threads as actually getting data from an sqlserver 2000 database.
The queries are actaully not very time consuming(sometimes these services
runs on servers which with heavy traffic.)

I havent used the syncronised object before, maybe I can use it somehow to
solve the issue. I will look more around this object....

If I set the timeout property and the thread does throw an exception. Am I
able to restart the exactly the same thread?

(Another information maybe i should have told you this at an earlier point.
The services can run stable more than a month before this kind "dieing"
thread fenomenal occurs. Sometimes more somtimes less and sometimes it
doesent occur at all.)

Thanx for your time and help.

Best regards
-Iceman
"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:Gl**************@cpmsftngxa07.phx.gbl...
Hi Iceman,

Usually it may be caused by waiting for an sychronized object.
Since in multiple thread programming, you must use the sychronized
mechanism to make the threads works properly.

So you may try to check if the "dead" thread is waiting for an synchronized object, or it attempted to access a resouce which is occupied by another
one thread or process.

Or you are execute an time-consuming procudure(e.g. query in the database)?
Can you tell me what are the "die" threads doing?

You may try to set the timeout value when you wait for a resource, so that
the thread will not wait infinitely.

If you have any concern on this issue,please post here.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #13
Hi Iceman,

Thank you for your reply.
If I set the timeout property and the thread does throw an exception. Am I
able to restart the exactly the same thread?
I think this due to how you handle the exception, when you run the thread,
the thread must has change the state of some variables or some other
resource, so you should reset them properly so that when the thread
restart, the thread running environment will be persists. That is to say,
if you abort a thread and restart it the thread will run from the beginning
of the thread proc, so it is important to maintain the original state of
the resource in the thread to get the same behavior.

To troubleshoot the problem, I think you may need to write an log to the
file after every function call in your "dead" thread, so that you can
locate where code line cause the problem. You may have a few tests to see
if the problem persists in the same code line.

Here is an link about multiple thread programming you may take a look.
Threading Tutorial
http://msdn.microsoft.com/library/de...us/csref/html/
vcwlkThreadingTutorial.asp

Based on my experience, the synchronized object is used to control the
multiple threads access one or more resource. e.g. you have an global
variable, if one thread will write it and another one will read it, this
will cause problem when the two threads do the read or write operation in
the mean time.
(Another information maybe i should have told you this at an earlier point.
The services can run stable more than a month before this kind "dieing"
thread fenomenal occurs. Sometimes more somtimes less and sometimes it
doesent occur at all.)


If there exists multiple threads accessing one resource and you did not use
the synchronized mechanism to synchronize the threads, the behavior is very
strange.

If this is a big project, I think you may need to call Microsoft Product
Support Services (PSS) for further help.

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #14
Hi Peter,

First of all I would like to thank you for your help and time. I have read
more about the syncronisation object and it seems like this is what I have
to implement to get "more stability".

Again thank you very much for your help.

Merry X-mas

Best regards
-Iceman
"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:fV**************@cpmsftngxa07.phx.gbl...
Hi Iceman,

Thank you for your reply.
If I set the timeout property and the thread does throw an exception. Am Iable to restart the exactly the same thread?
I think this due to how you handle the exception, when you run the thread,
the thread must has change the state of some variables or some other
resource, so you should reset them properly so that when the thread
restart, the thread running environment will be persists. That is to say,
if you abort a thread and restart it the thread will run from the

beginning of the thread proc, so it is important to maintain the original state of
the resource in the thread to get the same behavior.

To troubleshoot the problem, I think you may need to write an log to the
file after every function call in your "dead" thread, so that you can
locate where code line cause the problem. You may have a few tests to see
if the problem persists in the same code line.

Here is an link about multiple thread programming you may take a look.
Threading Tutorial
http://msdn.microsoft.com/library/de...us/csref/html/ vcwlkThreadingTutorial.asp

Based on my experience, the synchronized object is used to control the
multiple threads access one or more resource. e.g. you have an global
variable, if one thread will write it and another one will read it, this
will cause problem when the two threads do the read or write operation in
the mean time.
(Another information maybe i should have told you this at an earlier point.The services can run stable more than a month before this kind "dieing"
thread fenomenal occurs. Sometimes more somtimes less and sometimes it
doesent occur at all.)
If there exists multiple threads accessing one resource and you did not

use the synchronized mechanism to synchronize the threads, the behavior is very strange.

If this is a big project, I think you may need to call Microsoft Product
Support Services (PSS) for further help.

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #15

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

Similar topics

1
by: Eric Keij | last post by:
Hello, I have written a windows service in .NET which i want update. Is there an easy way to let a windows service update itself? I've written some test programs with the AppUpdater component...
1
by: caulker | last post by:
how can a windows service terminate itself? I have a windows service that reads in configuration settings from an XML file, but I'd like the service to automatically stop if it doesn't find a...
6
by: Leonardo Curros | last post by:
Hello, I would like to know what's the best way to restart one service. I would like to do it from the service itself. Is this possible? I try it with ServiceController.stop()...
3
by: Matt | last post by:
Is there an 'easy' way to have a service stop and restart itself? I currently have a seperate service running who's job is to watch the other service and restart it if there is a problem... can I...
1
by: Sergey Krutous | last post by:
Can you please help me to resolve the following issue: I developed a windows service. At start up (I have overriden OnStart method) it connects to a web service and if the connection fails the...
4
by: ThunderMusic | last post by:
Hi, We have many servers setup as a cluster. When one server crashes, another one take the relay... We want to know if it's possible (I suppose it is) to make a Windows service developed with .NET...
8
by: =?Utf-8?B?TWlrZVo=?= | last post by:
How Can Windows Service Application Reatarts itself? Thanks.
1
by: alexdrack | last post by:
Hello I'm building a windows service that grabs information from a website periodically, and the goal is to start all over again, when finding an exception, for example when internet disconnects....
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: 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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
Oralloy
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,...

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.