05. Code Tour, Mistakes, and Exercises
Recommended Code Tour
If you want to study the runtime in the best order, use this path:
src/InspectionPrototype.Application/State/AppState.csStart here to understand the full runtime snapshot.src/InspectionPrototype.Application/Guards/CommandGuards.csThis turns state into command semantics.src/InspectionPrototype.Application/Services/AppStateStore.csThis shows who owns mutation.src/InspectionPrototype.Application/Services/WorkflowService.csThis is the center of orchestration.src/InspectionPrototype.Application/Services/TelemetryPipelineService.csThis explains telemetry coalescing and background consumption.src/InspectionPrototype.Application/Services/FramePipelineService.csThis explains frame drops, fake defect generation, and active-run updates.src/InspectionPrototype.Presentation/ViewModels/MainViewModel.csThis shows how the UI projects runtime state safely.
That reading order mirrors the actual runtime story:
- state
- guards
- mutation owner
- orchestration
- background pipelines
- UI projection
Common Mistakes Newcomers Might Make
1. Adding Parallel Mutable UI State
It is tempting to add a new view-model property and treat it as the real source of truth for a feature.
In this repo, new runtime truth belongs in canonical AppState, then gets projected into the UI.
2. Putting Command Rules In The UI
It is tempting to decide button availability with ad hoc conditions in the presentation layer.
In this repo, command legality belongs in CommandGuards, derived from canonical state.
3. Blurring Stop, Abort, and Fault
These semantics are intentionally distinct:
- stop is graceful
- abort is immediate
- fault is unsafe and recovery-gated
If a change blurs those meanings, the runtime becomes less believable and less teachable.
4. Ignoring Backpressure
Telemetry and frames are not infinite. If a newcomer adds another stream without thinking about bounded channels or drop policy, the design will degrade quickly.
5. Updating WPF Objects From Background Threads
The runtime has several background producers. Direct UI updates from those producers would create thread-affinity problems and intermittent bugs.
The dispatch-and-project pattern exists to prevent that.
Exercises For Newcomers
Run the app and compare
StopandAbort. KeepWorkflowService.csopen and trace which path producesStoppedversusAborted.Inject a critical fault during an active run. Then trace how
OnFaultInjected(),AcknowledgeFault(),OnFaultCleared(), andRecoverAsync()cooperate.Watch pipeline counters during repeated runs. Then inspect
TelemetryPipelineServiceandFramePipelineServiceto see why drops and coalescing happen.Read
AppState.csand list which properties are durable outcomes versus live runtime observations. This helps separate coordination state from reporting state.Pick one command, such as
Start Run. Trace it fromMainWindow.xamltoMainViewModel, then toCommandGuards, then toWorkflowService.
Related Scenarios
- Scenario 01: Happy Path Inspection Run
- Scenario 02: Stop Versus Abort
- Scenario 03: Fault Injection and Recovery
- Scenario 05: Run History And Simulator Profiles
Related Lessons
- 01. Async Await Deep Dive
- 04. CancellationToken in Production - Real World
- 05. Streaming Pipelines in .NET - Real World
- 08. State Management in .NET - Real World
- 11. Background Processing in .NET - Real World
- 12. Observability in .NET Systems - Real World
- 20. Advanced Async Coordination
Diagram Brief
Title: Runtime study mapPurpose: Show a recommended reading and investigation path through the runtime codeAudience: newcomer studying the codebaseNodes: AppState, CommandGuards, AppStateStore, WorkflowService, TelemetryPipelineService, FramePipelineService, MainViewModelEdges: each file leads naturally to the next in the study order because it builds on the previous runtime conceptGrouping: State, coordination, streaming, projectionCaption: A good runtime study path follows responsibility flow, not file-system orderDestination file path:docs/diagrams/source/course-04-05-runtime-study-map.drawio