How to avoid abnormal stop of windows service?
I am using a third party component in window service. The CLR tries to recover the memory allocated to object of this component and some time it gives error but this error is not caught in try catch block anywhere, so window service is stopped abnormally.

I found following information in event viewer when service was stopped.

    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()


I want to know "How I can catch this error and stop the abnormal shutdown of window service"?
How to avoid abnormal stop of windows service?
===

I am using a third party component in window service. The CLR tries to recover the memory allocated to object of this component and some time it gives error but this error is not caught in try catch block anywhere, so window service is stopped abnormally.

I found following information in event viewer when service was stopped.

    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()


I want to know "How I can catch this error and stop the abnormal shutdown of window service"?