Skip to content

Commit

Permalink
Added Dispose override so that service handle can be disposed
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Patterson committed Mar 16, 2013
1 parent f0e20d1 commit afd1b14
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Topshelf/Runtime/Windows/WindowsServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public class WindowsServiceHost :
readonly HostEnvironment _environment;
readonly ServiceHandle _serviceHandle;
readonly HostSettings _settings;
int _deadThread;

int _deadThread;
bool _disposed;

public WindowsServiceHost(HostEnvironment environment, HostSettings settings, ServiceHandle serviceHandle)
{
if (settings == null)
Expand Down Expand Up @@ -202,6 +203,19 @@ protected override void OnShutdown()
_log.Fatal("The service did not shut down gracefully", ex);
throw;
}
}

protected override void Dispose(bool disposing)
{
if (disposing && !_disposed)
{
if (_serviceHandle != null)
_serviceHandle.Dispose();

_disposed = true;
}

base.Dispose(disposing);
}

void CatchUnhandledException(object sender, UnhandledExceptionEventArgs e)
Expand Down

0 comments on commit afd1b14

Please sign in to comment.