Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added exception if Start/Stop/Pause/Continue return false, added dire…

…ctory change to Start
  • Loading branch information...
commit 2aed1fa011bf7e1171e3a3f8c13bed71963b60ec 1 parent 567be13
Chris Patterson authored
Showing with 15 additions and 5 deletions.
  1. +15 −5 src/Topshelf/Runtime/Windows/WindowsServiceHost.cs
20 src/Topshelf/Runtime/Windows/WindowsServiceHost.cs
View
@@ -103,11 +103,18 @@ protected override void OnStart(string[] args)
{
try
{
- _log.Info("[Topshelf] Starting");
+ _log.Info("[Topshelf] Starting");
+
+ Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
+
+ _log.DebugFormat("[Topshelf] Current Directory: {0}", Directory.GetCurrentDirectory());
_log.DebugFormat("[Topshelf] Arguments: {0}", string.Join(",", args));
- _serviceHandle.Start(this);
+ if (!_serviceHandle.Start(this))
+ {
+ throw new TopshelfException("The service did not start successfully (returned false).");
+ }
_log.Info("[Topshelf] Started");
}
@@ -125,7 +132,8 @@ protected override void OnStop()
{
_log.Info("[Topshelf] Stopping");
- _serviceHandle.Stop(this);
+ if(!_serviceHandle.Stop(this))
+ throw new TopshelfException("The service did not stop successfully (return false).");
_log.Info("[Topshelf] Stopped");
}
@@ -142,7 +150,8 @@ protected override void OnPause()
{
_log.Info("[Topshelf] Pausing service");
- _serviceHandle.Pause(this);
+ if(!_serviceHandle.Pause(this))
+ throw new TopshelfException("The service did not pause successfully (returned false).");
_log.Info("[Topshelf] Paused");
}
@@ -159,7 +168,8 @@ protected override void OnContinue()
{
_log.Info("[Topshelf] Resuming service");
- _serviceHandle.Continue(this);
+ if(!_serviceHandle.Continue(this))
+ throw new TopshelfException("The service did not continue successfully (returned false).");
_log.Info("[Topshelf] Resumed");
}
Please sign in to comment.
Something went wrong with that request. Please try again.