C# – Window service automatically get stopped due to error

cnetwindows-services

I have an windows service that runs 24*7. This service use Renci.SshNet (third party dll) to connect to sftp server and downloading and uploading the files.

I got following information in event viewer. I check the log files and found that when this error come, the code was not running related to SFTP server.

I have written all the code in try catch block, so every error is logged into the log files.

Due to this error, windows service stopped.

I want to know the root cause of this issue and how I can modify the code so my service never get stopped again automatically.

Log Name:      Application
Source:        .NET Runtime
Date:          5/12/2012 10:49:12 AM
Event ID:      1026
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      FedEx-EDI-01
Description:
Application: Ess.SupplyChainService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Net.Sockets.SocketException
Stack:
   at Renci.SshNet.Session.WaitHandle(System.Threading.WaitHandle)
   at Renci.SshNet.Channels.Channel.Dispose(Boolean)
   at Renci.SshNet.Channels.ChannelSession.Dispose(Boolean)
   at Renci.SshNet.Channels.Channel.Dispose()
   at Renci.SshNet.Sftp.SubsystemSession.Dispose(Boolean)
   at Renci.SshNet.Sftp.SftpSession.Dispose(Boolean)
   at Renci.SshNet.Sftp.SubsystemSession.Finalize()

Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name=".NET Runtime" />
    <EventID Qualifiers="0">1026</EventID>
    <Level>2</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2012-05-12T14:49:12.000Z" />
    <EventRecordID>3723</EventRecordID>
    <Channel>Application</Channel>
    <Computer>FedEx-EDI-01</Computer>
    <Security />
  </System>
  <EventData>
    <Data>Application: Ess.SupplyChainService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Net.Sockets.SocketException
Stack:
   at Renci.SshNet.Session.WaitHandle(System.Threading.WaitHandle)
   at Renci.SshNet.Channels.Channel.Dispose(Boolean)
   at Renci.SshNet.Channels.ChannelSession.Dispose(Boolean)
   at Renci.SshNet.Channels.Channel.Dispose()
   at Renci.SshNet.Sftp.SubsystemSession.Dispose(Boolean)
   at Renci.SshNet.Sftp.SftpSession.Dispose(Boolean)
   at Renci.SshNet.Sftp.SubsystemSession.Finalize()
</Data>
  </EventData>
</Event>

Best Answer

You got a socket exception there - the stack trace you posted doesn't contain enough information as to why this happened.

Since the exception was not handled, the process terminated and of course the service stopped as result.

You need to find out why the exception occurred - add more logging and try to capture the incoming socket data.

Related Topic