Skip to main content

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.

LocationIssueFixImpact
PDFGen.csThread.Sleep(1000) during generation loop.await Task.Delay(1000)Frees thread during I/O wait.
MassActionOMGTSleep(500) in bulk processing loops.await Task.Delay(500)Prevents thread starvation during bulk edits.
WepEmailGeneratorSleep(500) likely for throttling.await Task.Delay(500)Higher email throughput capability.

[!TIP] Action Item: Search regex Thread\.Sleep\(\d+\) and replace with await Task.Delay(...) in all async compatible methods.


🔥 Priority 2: "Loop of Death" (CPU/DB Killers)

Goal: Stop "Carpet Bombing" the database. Problem: Nested loops triggering synchronous DB calls.

LocationMethodIssueRemediation
CenterControllerCompareCenterYear32+ Queries per request (N+1 nested).Stored Procedure or highly optimized LINQ (.Include()).
WepPartnerOMGTsTs()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.

LocationComponentIssueRemediation
OMGTInvoicingMaintenanceCheckMissingInvoicesRuns on request thread, risks timeout.Move to Hangfire (preferred) or HostingEnvironment.QueueBackgroundWorkItem.
CRMMaintenanceEmailExecute()Massive loops with Sleeps.Extract to dedicated Worker Service.

Execution Checklist

  • Phase 1 (Week 1): Replace all Thread.Sleep with Task.Delay in EITWEP.MaintenanceApp and WepNG_Business.
  • Phase 2 (Week 2): Refactor CompareCenterYear to use a single highly optimized query.
  • Phase 3 (Week 4): Proof of Concept for Hangfire integration to replace OMGTInvoicingMaintenance.