How to handle crash of windows service written in c#

Last post 05-15-2008 10:36 AM by jainadha. 6 replies.

Sort Posts:

  • How to handle crash of windows service written in c#

    05-07-2008, 10:21 AM
    • Loading...
    • jainadha
    • Joined on 05-07-2008, 10:12 AM
    • Posts 6

    I have a windows service that is written in C#. It reads text file which are created in a folder. It keeps watching the folder for if new text file is generated. If a new text file is generated, It parses the complete file and moves its content to database and finally the file is deleted. Now, if suppose this service crashes inbetween what should I do. So I was thinking of implementing another windows service which would monitor this service for its crash. But I dont know the way to really do it. This is my first dive to windows service and needs to solve this. If somebody could suggest me ideas, it would be really gud help to me.

    Thanks in advance.

  • Re: How to handle crash of windows service written in c#

    05-07-2008, 10:28 AM
    • Loading...
    • mgodoy_desenv
    • Joined on 02-22-2007, 7:12 PM
    • São Paulo - Brazil
    • Posts 430

    Use ServiceController class and check for Status property. However, the account of process need to be administrator.

  • Re: How to handle crash of windows service written in c#

    05-07-2008, 10:55 AM
    • Loading...
    • jainadha
    • Joined on 05-07-2008, 10:12 AM
    • Posts 6

    Hi..Thanks for your suggestion..I'll try to implement the same. This looks to be a good option to me.

  • Re: How to handle crash of windows service written in c#

    05-07-2008, 12:15 PM
    • Loading...
    • jainadha
    • Joined on 05-07-2008, 10:12 AM
    • Posts 6

    If I check for if my service is stopped, my other service will detect this and reads the file. Is that the way can we do it with service controller. In that case how would I know which file was my previous service working upon?

  • Re: How to handle crash of windows service written in c#

    05-07-2008, 12:29 PM
    Answer
    • Loading...
    • mgodoy_desenv
    • Joined on 02-22-2007, 7:12 PM
    • São Paulo - Brazil
    • Posts 430

    I recommend to you that the another service don“t reads the file, but just works like a monitor of another one.

    With ServiceControler you cannot read that file. It just handles Windows Services. You must to implement a routine to save the file in another place, cause any error occur.



    Exists another ways to do what you want beside of file. I recommend to you to use Message Queue of Windows. It works with transactional datas.

  • Re: How to handle crash of windows service written in c#

    05-07-2008, 2:33 PM

    Why not configure the service to auto-restart? 

  • Re: How to handle crash of windows service written in c#

    05-15-2008, 10:36 AM
    • Loading...
    • jainadha
    • Joined on 05-07-2008, 10:12 AM
    • Posts 6

    That service controller thing proved helpful as what I have done is the other service would see if the first service gets stopped. Once it finds that first service is stopped, the new service recreates dump of file which now are new files for my old service and it parses it. Thanks.

Page 1 of 1 (7 items)