Sometimes window service crash due to unhandled exception occur in the code. Which cause service to be on halt without any error log and we are unable to restart or stop the service in the windows.
In .net framework 4.5, Microsoft provides a method to handle the exception in the async event handler.
Simply write the below code snippet in the Start method of your window service and it’s done.
TaskScheduler.UnobservedTaskException += (object exSender, UnobservedTaskExceptionEventArgs eventArgs) =>
if (logger != null)
logger.Error("UnobservedTaskException occured: ", ex);