Skip to content

Commit 35e4674

Browse files
committed
Docs consistency
1 parent 178d18e commit 35e4674

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

Readme.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ The following improvements are included in this library:
1717
Through [NuGet](https://www.nuget.org/packages/CodeCaster.WindowsServiceExtensions/):
1818

1919
> Install-Package CodeCaster.WindowsServiceExtensions
20+
21+
## Usage
22+
These methods from this package allow your `IHostedService`s to tell the Windows Service Control Manager about errors, and respond to Windows Service events relating to sessions (user logon/logoff) and power state (shutdown/hibernate/resume):
23+
24+
* On your Host Builder, call `UseWindowsServiceExtensions()` instead of `UseWindowsService()`.
25+
* Instead of letting your service inherit `BackgroundService`, inherit from `CodeCaster.WindowsServiceExtensions.WindowsServiceBackgroundService`.
26+
* Implement `protected Task TryExecuteAsync(CancellationToken stoppingToken)` instead of `ExecuteAsync(CancellationToken stoppingToken)`.
27+
* Implement the method `public override bool OnPowerEvent(PowerBroadcastStatus powerStatus) { ... }` and do your thing when it's called with a certain status.
28+
* Implement the method `public override bool OnSessionChange(SessionChangeDescription changeDescription) { ... }` and do your thing when it's called with a certain status.
29+
30+
Do note that the statuses received can vary. You get either `ResumeSuspend`, `ResumeAutomatic` or both reported to `OnPowerEvent()`, never neither, after a machine wake, reboot or boot.
2031

2132
## Documentation
2233
For examples and more specific documentation, see https://codecasternl.github.io/WindowsServiceExtensions/.
@@ -32,16 +43,6 @@ Changes:
3243

3344
Extended upgrading docs: see https://codecasternl.github.io/WindowsServiceExtensions/upgrading-v2-v3.
3445

35-
## Usage
36-
These methods from this package allow your `IHostedService`s to respond to Windows Service events relating to sessions (user logon/logoff) and power state (shutdown/hibernate/resume):
37-
38-
* On your Host Builder, call `UseWindowsServiceExtensions()` instead of `UseWindowsService()`.
39-
* Instead of letting your service inherit `BackgroundService`, inherit from `CodeCaster.WindowsServiceExtensions.WindowsServiceBackgroundService`.
40-
* Implement the method `public override bool OnPowerEvent(PowerBroadcastStatus powerStatus) { ... }` and do your thing when it's called with a certain status.
41-
* Implement the method `public override bool OnSessionChange(SessionChangeDescription changeDescription) { ... }` and do your thing when it's called with a certain status.
42-
43-
Do note that the statuses received can vary. You get either `ResumeSuspend`, `ResumeAutomatic` or both reported to `OnPowerEvent()`, never neither, after a machine wake, reboot or boot.
44-
4546
# Contributing
4647
Please file an issue or PR. Even if you use this and are happy with it.
4748

docs/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Through [NuGet](https://www.nuget.org/packages/CodeCaster.WindowsServiceExtensio
1616
> Install-Package CodeCaster.WindowsServiceExtensions
1717

1818
## Why should you use this?
19-
Using .NET's [`UseWindowsService()`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.windowsservicelifetimehostbuilderextensions.usewindowsservice?view=dotnet-plat-ext-6.0) (from the Platform Extensions package `Microsoft.Extensions.Hosting.WindowsServices`) and [`Microsoft.Extensions.Hosting.BackgroundService`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.backgroundservice?view=dotnet-plat-ext-6.0) from `Microsoft.Extensions.Hosting.Abstractions`, a usual Windows Service program hosting some long-running background tasks could look like this:
19+
Using .NET's [`UseWindowsService()`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.windowsservicelifetimehostbuilderextensions.usewindowsservice?view=dotnet-plat-ext-6.0) (from the Platform Extensions package `Microsoft.Extensions.Hosting.WindowsServices`) and [`Microsoft.Extensions.Hosting.BackgroundService`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.hosting.backgroundservice?view=dotnet-plat-ext-6.0) from `Microsoft.Extensions.Hosting.Abstractions`, a typical Windows Service program hosting some long-running background tasks could look like this:
2020

2121
```csharp
2222
var hostBuilder = new HostBuilder()
@@ -112,7 +112,7 @@ public class MyCoolBackgroundService : WindowsServiceBackgroundService
112112
}
113113

114114
// This one tells you when we're shutting down or resuming from semi-hibernation
115-
protected override void OnPowerEvent(PowerBroadcastStatus powerStatus)
115+
public override void OnPowerEvent(PowerBroadcastStatus powerStatus)
116116
{
117117
// The lifetime will log "OnPowerEvent: {powerStatus}"
118118
@@ -130,7 +130,7 @@ public class MyCoolBackgroundService : WindowsServiceBackgroundService
130130
}
131131

132132
// React to logon/logoff/...
133-
protected override void OnSessionChange(SessionChangeDescription changeDescription)
133+
public override void OnSessionChange(SessionChangeDescription changeDescription)
134134
{
135135
// The lifetime will log "OnSessionChange: {changeDescription.SessionId}, {changeDescription.Reason}"
136136

0 commit comments

Comments
 (0)