Async Migration Plan: Tactical Execution
Overview
This document outlines the specific, high-priority targets for applying the Async Strategy. It is derived from codebase archeology (Jan 2026).
🚦 Priority 1: The "Fake Async" (Quick Wins)
Goal: Immediate server throughput improvement.
Problem: Code explicitly blocks threads using Thread.Sleep, treating the web server like a console application.
| Location | Issue | Fix | Impact |
|---|---|---|---|
PDFGen.cs | Thread.Sleep(1000) during generation loop. | await Task.Delay(1000) | Frees thread during I/O wait. |
MassActionOMGT | Sleep(500) in bulk processing loops. | await Task.Delay(500) | Prevents thread starvation during bulk edits. |
WepEmailGenerator | Sleep(500) likely for throttling. | await Task.Delay(500) | Higher email throughput capability. |
[!TIP] Action Item: Search regex
Thread\.Sleep\(\d+\)and replace withawait Task.Delay(...)in allasynccompatible methods.
🔥 Priority 2: "Loop of Death" (CPU/DB Killers)
Goal: Stop "Carpet Bombing" the database. Problem: Nested loops triggering synchronous DB calls.
| Location | Method | Issue | Remediation |
|---|---|---|---|
CenterController | CompareCenterYear | 32+ Queries per request (N+1 nested). | Stored Procedure or highly optimized LINQ (.Include()). |
WepPartnerOMGTs | Ts() | 1000 DB Connections opened/closed in loop. | Batch Process: Refactor service to accept List<int> IDs. |
⚙️ Priority 3: Stability & Maintenance
Goal: Prevent background tasks from crashing the Web App. Problem: Long-running maintenance tasks executing in the Web Request context.
| Location | Component | Issue | Remediation |
|---|---|---|---|
OMGTInvoicingMaintenance | CheckMissingInvoices | Runs on request thread, risks timeout. | Move to Hangfire (preferred) or HostingEnvironment.QueueBackgroundWorkItem. |
CRMMaintenanceEmail | Execute() | Massive loops with Sleeps. | Extract to dedicated Worker Service. |
Execution Checklist
- Phase 1 (Week 1): Replace all
Thread.SleepwithTask.DelayinEITWEP.MaintenanceAppandWepNG_Business. - Phase 2 (Week 2): Refactor
CompareCenterYearto use a single highly optimized query. - Phase 3 (Week 4): Proof of Concept for Hangfire integration to replace
OMGTInvoicingMaintenance.