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

Posted on 2012-08-29
Last Modified: 2012-09-03
Hi all,

I have a windows service written in 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.


Question by:resourcesys
    LVL 83

    Expert Comment

    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.

    Accepted Solution

    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.



    Author Closing Comment

    Soultion solves problem.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now