• About
  • Privacy Policy
  • Utilities
Darchuk.NET

Concurrency

CancellationTokens

November 2, 2018 by Robert 1 Comment

In C# asynchronous programming, a CancellationToken allows you to stop a Task.  This is especially useful if you have many Tasks running and want to gracefully shut down the program, or if you want to add a timeout to a Task. via GIPHY Creation CancellationTokens are created from a CancellationTokenSource. via GIPHY Usage The token … [Read more…]

Posted in: .NET Core, Asynchronous, C#, Concurrency Tagged: async, await, C#, CancellationToken, CancellationTokenSource, Concurrency, OperationCanceledException, TaskCanceledException

Throttling execution through BlockingCollection

July 20, 2018 by Robert Leave a Comment

BlockingCollection is essentially a queue that provides a thread-safe way to consume items.  You can put it into a loop and consume the items one at a time, throttling execution and potentially preventing your system from being overwhelmed. I use these all the time, but most recently I built it in to a metric collection … [Read more…]

Posted in: C#, Concurrency Tagged: Blocking, BlockingCollection, C#, Concurrency, Execution, Optimization, Process, Queue, Throttle

Thread-Safe Atomic Operations

June 29, 2018 by Robert Leave a Comment

There’s been more than a couple times where I’ve wanted to use the Parallel class to take a collection and rip through it with multiple threads, but I’ve struggled with how to log the progress (especially the count of objects processed) easily. Interlocked .NET actually provides the solution in a static class called Interlocked, located … [Read more…]

Posted in: .NET Core, ASP.NET, Asynchronous, C#, Concurrency Tagged: .NET, C#, Concurrency, Thread, Thread Safe, threading

Moq sequential calls

January 26, 2018 by Robert 1 Comment

Say that you’re unit testing and you want a mocked interface to behave differently for different calls to the same method. I was trying to test a TCP listener loop – a TcpListener waits for an incoming connection, does something with it, and then goes back to listening.  In essence, the loop will last until … [Read more…]

Posted in: Asynchronous, C#, Unit Testing Tagged: C#, Concurrency, Moq, unit testing

Recent Posts

  • Allowing trailing JSON commas in ASP.NET Core 3
  • YADNC3JSG–Yet Another .NET Core 3.0 JSON Serializer Gotcha
  • Logging in a .NET Core 3 SignalR client
  • .NET Core 3 unit testing project sdk
  • .NET Core 3.0 Upgrade–New JSON Serializer Gotchas

Recent Comments

  1. Robert on C# Setting Socket Keep-Alive
  2. Oliver Schramm on C# Setting Socket Keep-Alive
  3. John Anderson on Waiting for a keypress asynchronously in a C# console app
  4. Ronald Garlit on .NET Core 3 unit testing project sdk
  5. Ronald Garlit on .NET Core 3 unit testing project sdk

Copyright © 2025 Darchuk.NET.

Omega WordPress Theme by ThemeHall