Run one task iteration¶
| Field | Value |
|---|---|
| Operation ID | OP-06 |
| Trigger | Execute the worker loop step 2 |
| Inputs | stoppingToken |
| Outputs | None on success; task-runner exceptions are caught and delegated to the error handler, which may itself throw and propagate out of this operation |
| Primary components | ServiceWorker<T>.RunTaskAsync |
| Entry point | src/SAIF.NetCore.WindowsService/SAIF.NetCore.WindowsService/SAIF.NetCore.WindowsService/ServiceWorker.cs |
Steps¶
- Invoke the consumer task with
await TaskRunner.Run(stoppingToken). - Delegation -> consumer code implementing
SAIF.NetCore.ServiceContracts'sIServiceTaskRunner.Run(CancellationToken). ServiceContracts defines no steps of its own; the consumer supplies the business logic. - Catch every exception (
catch (Exception ex)) and callawait HandleTaskError(ex)(see Handle a task error) (WS-BR-08). - Branch: an
OperationCanceledExceptionthrown by a runner that honorsstoppingTokenduring shutdown is also treated as a task error — it is logged as an error and, unless exempted, triggers anotherStopAsync*. - Branch:
HandleTaskErroritself is not guarded by a further try/catch here — an exception raised while evaluating the exemption predicate, building the message, callingErrorHandler.HandleError, or callingServiceHost.StopAsyncpropagates out ofRunTaskAsyncand out of the worker'sExecuteAsync; it is not absorbed (see Handle a task error failure branches).
Process flow¶
flowchart TD
Start([RunTaskAsync]) --> Invoke[await TaskRunner.Run stoppingToken]
Invoke --> Threw{Exception thrown?}
Threw -->|No| Done([Return normally])
Threw -->|Yes| Handle[HandleTaskError ex]
Handle --> HandleThrew{HandleTaskError threw?}
HandleThrew -->|No| Done
HandleThrew -->|Yes| Propagate(["Exception propagates out of RunTaskAsync and ExecuteAsync"])
Failure and edge-case behavior¶
- A
NullReferenceExceptionfrom anullTaskRunner(see Construct a service worker) is caught here, like any other exception. - A cooperative-cancellation
OperationCanceledExceptionduring shutdown is treated identically to an unexpected error and may trigger an additionalStopAsynccall, even though the host is already stopping*. - An exception thrown inside
HandleTaskErroris not absorbed by this operation; it propagates out ofRunTaskAsyncand the worker'sExecuteAsync, skipping whatever shutdown step would otherwise have run.
Related documentation¶
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.
Sources¶
src/SAIF.NetCore.WindowsService/SAIF.NetCore.WindowsService/SAIF.NetCore.WindowsService/ServiceWorker.cs