?
Solved

Detect when a thread/tick has crashed in a windows service

Posted on 2012-08-29
3
Medium Priority
?
706 Views
Last Modified: 2012-09-03
Hi all,

I have a windows service written in asp.net 2 (VB.NET).

When the service starts, a timer is created and everytime the timer ticks a block of code is executed.

This code block accesses a database, incase there is a problem the SQL is executed within a try catch block and any error that occurs is written to a text file.

The issue I'm having is that when this happens, even though the sql statement is in a try catch block, the tick/thread crashes.

this is a problem because for every tick, I disable the timer, then re-enable it when the code block has executed.

So, I need to know is there a way to detect if the tick/thread has crashed or if an error handler can be added?

I would like to avoid having one big try catch statement.

Thanks.

resourcesys.
0
Comment
Question by:resourcesys
  • 2
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38345854
Can you show us the code? Are you sure your catch is handling all the exceptions? May be add a Finally block to your try to enable the timer again.
0
 

Accepted Solution

by:
resourcesys earned 0 total points
ID: 38346015
Hi CodeCruiser,

Thanks for your reply.

We have decided to just go with using Environment.Exit(1) after writing our error message.

This way, the service will stop, then the server will automatically restart after a minute, which is something we prefer.

Thanks.

resourcesys.
0
 

Author Closing Comment

by:resourcesys
ID: 38360325
Soultion solves problem.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question