473,799 Members | 3,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Errors in services. How should you handle them?

I'm writing a realtime monitoring application acting as a Windows service.
This service communicates to some instrumentation via a third party dll. TCP
is the transport mechanism over the network.
What I want to know is how should errors be handled in Windows services? I
foresee problems with this sort of application, especially with the tcp
side.
The service should be able to recover from errors as it's going to be sited
in places where there are power outages. I expect the network to go down
etc.
Should users be alerted if connection can't be achieved? When?
Nov 17 '05 #1
4 1361
Unfortunately Claire, only you can decide if and when you should notify
someone.

Once you have decided the ifs and whens, the next question becomes the hows
and whats. i.e. How do I notify the notifiee and what do I notify them of.
The answers to these are dictated by the mechanisms that are available to
your service and what information is available. Basically, it will come down
to personal preference.
"Claire" <as*******@ntlw orld.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I'm writing a realtime monitoring application acting as a Windows service.
This service communicates to some instrumentation via a third party dll.
TCP is the transport mechanism over the network.
What I want to know is how should errors be handled in Windows services? I
foresee problems with this sort of application, especially with the tcp
side.
The service should be able to recover from errors as it's going to be
sited in places where there are power outages. I expect the network to go
down etc.
Should users be alerted if connection can't be achieved? When?

Nov 17 '05 #2
On Fri, 1 Apr 2005 08:05:19 +0100, Claire wrote:
I'm writing a realtime monitoring application acting as a Windows service.
This service communicates to some instrumentation via a third party dll. TCP
is the transport mechanism over the network.
What I want to know is how should errors be handled in Windows services? I
foresee problems with this sort of application, especially with the tcp
side.
The service should be able to recover from errors as it's going to be sited
in places where there are power outages. I expect the network to go down
etc.
Should users be alerted if connection can't be achieved? When?


I wrote a lot of service applications in the past (in C++). What I can tell
you from experience:
- use logfiles (or log to a database), where you log the
important things happening in your service
- alert someone, if a severe error happens that needs
user/administrator interaction in anyway.
- make it configurable (who is alerted, when, etc.)

In a .NET application, I strongly suggest to use Log4Net
(http://logging.apache.org/log4net) to do that. Using log4net you also get
very good configuration possibilities to configure what kind of errors are
logged to which device and when shall someone (and who) be alerted.

Instead of Log4Net you could also use the Logging Appliaction Block of the
Enterprise Library
(http://msdn.microsoft.com/library/de...ml/entlib.asp).

hth
--
Claudio Grazioli
http://www.grazioli.ch
Nov 17 '05 #3
I wrote a similar service for an enterprise application that dealt with the
same kinds of problems you are facing here: power outtages, lost
connections, etc. Here are a few things to keep in mind while you design
your service:

1) Make your service fail safe from the stand point that if network is not
available it can just idle and periodically check for network availability,
your service should not "hang" or "crash" if the network goes down. This
will involve wrapping all of your network calls with error handlers so that
you won't be using any sockets that are disconnected or in an invalid state.

2) Logs are really useful. If possible log all acitivity to a local
database. For example: Service start time, service shutdown time, and if
the network goes up and down log the time the network became unavailable and
when it was detected up again. Log messages are extremely useful when you
have to trace through a problem that may not be necessarily happening with
your code/design but instead with the network that is connected to the
server.

3) Assign priority to log entries such as Notice, Caution, and Critical
depending on the kinds of problems you foresee encountering during operation
of the server. In the product I worked on the logs were available through a
web interface and color coded accordingly, it was very easy to go straight
to critical and see what happened leading up to that critical log.

4) If your service is going to be multithreaded you add another dimension of
complexity. This is not a bad thing but you must make sure that your
service main thread is able to recycle threads that crash or terminate
unexpectedly. You should be able to gracefully deallocate the memory from a
crashed thread and respawn it to continue what it had been doing previously.
This is not something that is trivial to do.

5) Lastly don't leave any connections open in an environment like this.
Crashing because of a power outtage may actually corrupt the files or
databases for which you are writing to when it happens. So when making
entries into a database or file, if it is not a performance hit go with the
open->write->close sequence and try to make each transaction as atomic as it
can be.

Project I worked on ran a multithreaded service in a fairly hostile
environment where it received data from one end, processed the data, and
sent data to another end point where it needed to be able to detect if the
data received was valid (not garbled) and that the receving system was
available (not crashed) and if not it would have to queue the data until it
became available (each transaction carried a $$$ amount so no transactions
could be lost). In addition locations were often hostile at the very least
and prone to lightning strikes and other hazards, go figure systems running
in closets at air force bases.

This is really long, but I hope it will give you a few things to consider as
you design your system.

Alex
"Claire" <as*******@ntlw orld.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I'm writing a realtime monitoring application acting as a Windows service.
This service communicates to some instrumentation via a third party dll.
TCP is the transport mechanism over the network.
What I want to know is how should errors be handled in Windows services? I
foresee problems with this sort of application, especially with the tcp
side.
The service should be able to recover from errors as it's going to be
sited in places where there are power outages. I expect the network to go
down etc.
Should users be alerted if connection can't be achieved? When?

Nov 17 '05 #4
Thanks to everyone
Yes Alex, just sounds like my system except I don't have direct access to
the ports as I have to communicate via the instrument vendors DLL ;o(
I just hope the developer's code is well behaved.

Claire
Nov 17 '05 #5

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

Similar topics

5
3338
by: Francis Lavoie | last post by:
Is it possible to restart windows services? (remotely and locally) Because I have a little script that retreive the LastWaitTimeout key of the automatic update, delete that key if it out schedule for our production needs. But still the service need to be restarded if I want that key to be reset, when Win Update will resynchronize with the sus server for new update. Thankx
1
439
by: Avanish Pandey | last post by:
Hello All We have 3 differen services (in 3 different server) Service A,B,C . We want to implement distributed transaction when call methods of B and C from A. Is it possible? if yes then how? I have read the doc regarding this: http://www.developer.com/net/asp/article.php/3385631 but it will not work when methods are in different services on
6
1809
by: Aaron | last post by:
I would like to write a program that finds all asp.net errors in iis logs? what characteristics should i look for? (a line in the log that has the error?) what about sql errors? Thanks in advance, Aaron
4
3317
by: Dave | last post by:
Hi folks, I am trying to develop a routine that will handle sphere-sphere and sphere-triangle collisions and interactions. My aim is to develop a quake style collision engine where a player can interact with a rich 3D environment. Seem to be 90% of the way there! My problems are related to calculations where the result tends to zero (or another defined limit.) Have loads of cases where this kind of interaction occurs but this one
4
2475
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called themselves, or should i return a code to main and handle the error there? If i don't return them to main, except for the structure, what use is the main function except for calling functions?
2
2545
by: Matt | last post by:
Hello all, The app we are working on uses custom errors extensively to provide friendly error pages to users whilst logging the actual exceptions behind the scenes. However.... We are now having to integrate some Web services into the application using the existing architecture. These Web services are secured using Forms Authentication. Hence, we need to turn the default behavior of Forms Authentication (redirects to login pages, etc)...
4
1259
by: Christoph Duesmann | last post by:
Hi ! I wan't to code a service which will be installed on some clients in our network. The service should have the following features : - Scan all properties of the Client (Hardware, Software etc) - Create a log (eg. logfile.txt) - Optional : Insert the data directly in an SQL-Database - All these functions should occur, when a Timer elapsed or when I send a
3
2038
by: clintonb | last post by:
Some programmers, and even Microsoft documents, say you should only throw exceptions for exceptional situations. So how are others handling all the other unexceptional errors? How are you propagating errors up the call stack? In the past, in my C++ code, I used to throw exceptions for ALL errors, exceptional or not. It seemed like a nice clean method for detecting, handling, and propagating errors. You can find multitudes of articles...
8
5579
by: ImOk | last post by:
I just have a question about trapping and retrying errors especially file locking or database locks or duplicate key errors. Is there a way after you trap an error to retry the same line that cause the error? In many other languages you have the option of rertying certain errors. In effect, its like a return to the exact same line. You can then retry certain # of times and then produce an error if it keeps failing.
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10238
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,...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
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...
0
6809
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();...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
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...

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.