473,395 Members | 1,441 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,395 software developers and data experts.

service coded in managed C++; how are restarts handled?

Hello,

I am new to this game so please bear with me. I have just written a simple
application as a service using Visual Studio and managed C++. I wish the
process to run in the background and to not use a GUI **ever**. It just
runs. And if it fails for ANY reason then it is simply to be restarted. I
need some help with this please.

I have already found about _CrtSetReportMode and how I need to call it to
suppress the popups I would otherwise get on application crash. But I am
not sure how to make it so that the application is restarted. If it
crashes the restart should be immediate. Also, if possible I would like it
logged in the event log. Please, how is it done?

Regards,

Andrew Marlow

Oct 3 '06 #1
6 1326
"A Marlow" <us****@marlowa.plus.comwrote in message
news:pa****************************@marlowa.plus.c om...
I am new to this game so please bear with me.
You have come to a pretty civil place.
I have just written a simple application as a service
using Visual Studio and managed C++. I wish the
process to run in the background and to not use a GUI
**ever**. It just runs. And if it fails for ANY reason then
it is simply to be restarted. I need some help with this please.
OK.
But I am not sure how to make it so that the application is
restarted. If it crashes the restart should be immediate.
At the risk of stating the obvious, a dead application can't resurrect
itself. So you need some external agent to do that. You could write one but
then that begs the question as to what to do if it fails. :-)

So, usually developers just install their services and leave the restart to
the service control manager. The properties dialog for every service has a
recovery tab wherein you can set the restart policy.

In native code, you can set the restart policy by calling
ChangeServiceConfig2(). I'm not sure how that is done in managed code.
Someone else may chime in here with that info if you are looking for a
managed solution.

Regards,
Will

Oct 3 '06 #2
"William DePalo [MVP VC++]" wrote:
You have come to a pretty civil place.
On most days, yes. ;)
In native code, you can set the restart policy by calling
ChangeServiceConfig2(). I'm not sure how that is done in managed code.
Someone else may chime in here with that info if you are looking for a
managed solution.
From what I can tell, the service restart policy has not yet been exposed
directly to the CLR. As I see it, you have two options:

1. Use P/Invoke on ChangeServiceConfig2(), and set the restart policy that
way, or,
2. Create a second small application or service, whose only purpose in life
is to monitor the first service and restart it if it should fail.

I'd prefer option 1, since you'd only have to set the policy once and you
wouldn't incur the overhead of a second application running.

Sean
Oct 4 '06 #3

William DePalo [MVP VC++] wrote:
"A Marlow" <us****@marlowa.plus.comwrote in message
news:pa****************************@marlowa.plus.c om...
But I am not sure how to make it so that the application is
restarted. If it crashes the restart should be immediate.

At the risk of stating the obvious, a dead application can't resurrect
itself. So you need some external agent to do that.
I was hoping that Windoze would come with a working facility for this.
I found the recovery tab in service properties but I have had
difficulty in making it work.
So, usually developers just install their services and leave the restart to
the service control manager. The properties dialog for every service has a
recovery tab wherein you can set the restart policy.
When I tried I found the only thing that actually seems to cause it to
restart was by setting the fail count to zero and action on first
failure to restart, then setting the polling frequency to 1 minute.
With these set and with the service deliberately rigged to core dump,
it got restarted EVERY minute. Whilst this is what I want, I was
suprised, considering I told Windoze to only restart on *first*
failure.
In native code, you can set the restart policy by calling
ChangeServiceConfig2(). I'm not sure how that is done in managed code.
Someone else may chime in here with that info if you are looking for a
managed solution.
Hmm. I would like this to be done externally if poss, but thanks for
the tip.

Regards,

Andrew

Oct 4 '06 #4
Whilst this is what I want, I was
suprised, considering I told Windoze to only restart on *first*
failure.
Does it make you feel 'l337' to say 'windoze'?
;-)

--
Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"

Oct 4 '06 #5
<ap***@student.open.ac.ukwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
I was hoping that Windoze would come with a working facility for this.
_Windows_ does come with a working facility for doing this both at a user
level and at a programmatic level.
I found the recovery tab in service properties but I have had
difficulty in making it work.
Work harder.

Regards,
Will
Oct 4 '06 #6
On Wed, 04 Oct 2006 11:16:40 -0400, William DePalo [MVP VC++] wrote:
<ap***@student.open.ac.ukwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
>I was hoping that Windoze would come with a working facility for this.

_Windows_ does come with a working facility for doing this both at a user
level and at a programmatic level.
>I found the recovery tab in service properties but I have had
difficulty in making it work.

Work harder.
I have. And it now works. Not quite the way I expected but I can get a
service to dynamically restart and not invoke any popups when it fails.
This is what I wanted. I had heard rumours that the facility doesn't work
but those rumours must be false.
>
Regards,
Will
Oct 5 '06 #7

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

Similar topics

2
by: Andy | last post by:
hi all, I've created a windows server that will watch to make sure another process stays running. It looks for the Process and attaches to the Exited event, which works fine. If the program...
12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
3
by: zxo102 | last post by:
Hi there, I have a python application (many python scripts) and I start the application like this python myServer.py start in window. It is running in dos window. Now I would like to put it...
4
by: kkt49 | last post by:
# vim: et sw=4 ts=8 sts from wxPython.wx import * import sys, os, time import pywintypes import win32serviceutil import win32service import win32event import win32process
0
by: MichiMichi | last post by:
My services shows once a while the infamous error "Service Unavailable" (http 503 error). This error happens only if my asp.net application encounters a problem with the SQL Server. In my case it...
2
by: =?Utf-8?B?TWljaGVsIFNjaGF3YW5u?= | last post by:
Hi all, I try to create a service witch handle the session switch events: Lock, unlocked etc... I can do this with a standard executable like this (it's just an example):...
6
by: Michael Tissington | last post by:
Using Visual Studio 2008 can someone point me to an example to create a cgi web service in C# ? Thanks.
2
by: Peter | last post by:
Is there a way to automatically update a Windows .NET service, kind of like Click-Once or put a file in the directory and the service would restart it's self and replace the executables or at least...
0
by: Ashok Iyer | last post by:
This is instalation of oracle 9i on windows XP. I found a strange problem. My apache/http service is misbehaving. when the hpps service is started the error.log in /apache/apache/log directory...
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:
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
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:
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
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.