⚠️ Malware / Trojaner / Viren9 Proofpoint alternatives. Pros & cons of the leading options(24.08.2026 um 11:27 Uhr)
⚠️ Malware / Trojaner / VirenWhat the DfE’s cyber security update means for multi-academy trusts(24.08.2026 um 19:13 Uhr)
⚠️ Malware / Trojaner / VirenBuilding a ransomware decision tree before the call comes in(11.09.2026 um 07:30 Uhr)
🕵️ SicherheitslückenAutomox Mitigation Worklets cut endpoint exposure to unpatchable flaws(11.09.2026 um 09:48 Uhr)
⚠️ Malware / Trojaner / VirenFake Codex Download Uses Google Sites to Deliver macOS Malware(24.08.2026 um 17:00 Uhr)
⚠️ Malware / Trojaner / VirenFake Minecraft Clients Deliver WeedHack Malware Despite Infrastructure Takedown(25.08.2026 um 12:30 Uhr)
🕵️ SicherheitslückenFour in Five AI Tools Run with No IT Oversight, New Research Finds(26.08.2026 um 15:00 Uhr)
⚠️ Malware / Trojaner / VirenTortoiseshell Expands Malware Toolset With New Backdoor, SSH Tunnel(26.08.2026 um 16:30 Uhr)
⚠️ Malware / Trojaner / Viren9 Proofpoint alternatives. Pros & cons of the leading options(24.08.2026 um 11:27 Uhr)
⚠️ Malware / Trojaner / VirenWhat the DfE’s cyber security update means for multi-academy trusts(24.08.2026 um 19:13 Uhr)
⚠️ Malware / Trojaner / VirenBuilding a ransomware decision tree before the call comes in(11.09.2026 um 07:30 Uhr)
🕵️ SicherheitslückenAutomox Mitigation Worklets cut endpoint exposure to unpatchable flaws(11.09.2026 um 09:48 Uhr)
⚠️ Malware / Trojaner / VirenFake Codex Download Uses Google Sites to Deliver macOS Malware(24.08.2026 um 17:00 Uhr)
⚠️ Malware / Trojaner / VirenFake Minecraft Clients Deliver WeedHack Malware Despite Infrastructure Takedown(25.08.2026 um 12:30 Uhr)
🕵️ SicherheitslückenFour in Five AI Tools Run with No IT Oversight, New Research Finds(26.08.2026 um 15:00 Uhr)
⚠️ Malware / Trojaner / VirenTortoiseshell Expands Malware Toolset With New Backdoor, SSH Tunnel(26.08.2026 um 16:30 Uhr)

🔧 Programmierung 🕛 vor 2 Monaten 3 Min Lesezeit
0

Synchronous vs asynchronous in .NET core - how decide

↗ Quelle (dev.to)
🗣️ Stimme:




Rule of thumb



If your action waits on something external, make it async. If it’s instant CPU, keep it sync; for expensive CPU, offload.






The core idea





  • Async shines for I/O-bound work (DB calls, HTTP calls, queues, files). It frees the request thread while waiting, so the server can serve more requests with the same thread pool.


  • Sync is fine for trivial, short CPU work (formatting, small calculations) where you’re not awaiting anything and the handler returns in a few milliseconds.






When to choose async




  • You call EF Core (SaveChangesAsync, ToListAsync), HttpClient, Azure SDK (ServiceBusClient, BlobClient), file I/O, or any API with Async methods.

  • You expect latency from a dependency (tens–hundreds of ms).

  • You need cancellation and timeouts (propagate HttpContext.RequestAborted).






When sync is acceptable




  • The action is pure CPU and trivial (e.g., quick math, mapping, input validation) and returns immediately.

  • There are no I/O waits and no benefit from freeing the thread.




If it’s CPU-heavy (image processing, big JSON transforms), do not just make it async—offload to a background queue/worker or a separate compute service. Async won’t make CPU faster.







Pitfalls to avoid





  • Don’t block async: never use .Result / .Wait() on Tasks (deadlocks/thread-pool starvation).


  • Async all the way down: if the controller is async, downstream calls should be too.


  • Don’t fake async: returning Task.Run around synchronous I/O just burns threads.


  • Keep concurrency bounded when fanning out to multiple I/O calls.






Mini decision checklist





  1. Any I/O? → Use async (end-to-end).

  2. Pure CPU?





  • Tiny (≤ a few ms) → Sync is fine.


  • Heavy/variable → Offload to background worker; controller returns 202/Location or uses a queue.






ASP.NET Core examples



Async (I/O-bound) — recommended




CODE
[ApiController]
[Route("orders")]
public class OrdersController : ControllerBase
{
private readonly OrdersDbContext _db;
private readonly HttpClient _http;

public OrdersController(OrdersDbContext db, IHttpClientFactory f)
{
_db = db;
_http = f.CreateClient("catalog");
}

[HttpGet("{id}")]
public async Task<ActionResult<OrderDto>> Get(string id, CancellationToken ct)
{
var order = await _db.Orders.FindAsync([id], ct);
if (order is null) return NotFound();

// Call another service
var resp = await _http.GetAsync($"/inventory/{order.Sku}", ct);
resp.EnsureSuccessStatusCode();
var inv = await resp.Content.ReadFromJsonAsync<InventoryDto>(cancellationToken: ct);

return Ok(new OrderDto(order, inv));
}
}






Sync (trivial CPU) — acceptable




CODE
[HttpGet("ping")]
public ActionResult<string> Ping() => "pong"; // no I/O, returns immediately






CPU-heavy work — offload rather than “asyncifying”




CODE
// Controller: accept request, enqueue, return 202
[HttpPost("render")]
public async Task<IActionResult> Render(RenderRequest req, [FromServices] IBackgroundQueue queue)
{
var jobId = Guid.NewGuid().ToString("N");
await queue.EnqueueAsync(jobId, req);
return Accepted($"/render/{jobId}");
}

// Hosted service: single place that uses CPU, bounded concurrency
public class RenderWorker : BackgroundService
{
private readonly IBackgroundQueue _q;
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await foreach (var job in _q.DequeueAllAsync(stoppingToken))
{
// CPU-bound work here (e.g., image/video), controlled degree of parallelism
}
}
}









Tuning & tips




  • Pass CancellationToken from HttpContext.RequestAborted.

  • Use IHttpClientFactory and async Azure SDKs.

  • For streaming, expose IAsyncEnumerable<T> or chunked responses (async).

  • In ASP.NET Core there’s no UI SynchronizationContext, so ConfigureAwait(false) is usually unnecessary.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
9 Proofpoint alternatives. Pros & cons of the leading options
1 Quelle
What the DfE’s cyber security update means for multi-academy trusts
1 Quelle
Coffee with the Council Podcast: Celebrating 20 Years of Securing Payment Data
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Synchronous vs asynchronous in .NET core - how decide

Thematisch verwandte Begriffe: Synchronous, asynchronous, core, decide · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...