• About
  • Privacy Policy
  • Utilities
Darchuk.NET

Asynchronous

SignalR Strongly-Typed Hubs

July 19, 2019 by Robert 3 Comments

Previously I talked about how to set up the server side of SignalR for facilitating real-time communication.  One of the parts that I don’t particularly care for in that default implementation is that the hub methods (the messages that are sent to connected clients) are identified by strings.  Sure, you could create some string constants … [Read more…]

Posted in: .NET Core, ASP.NET, Asynchronous, C#, SignalR, Web Development Tagged: C#, Magic Strings, Realtime, SignalR

Waiting for a keypress asynchronously in a C# console app

February 8, 2019 by Robert 2 Comments

This one’s kind of specific, but sometimes when you’re writing a console app that does a lot of asynchronous stuff, and you want to cancel it at any time by pressing escape.  via GIPHY However, Console.ReadKey is blocking… so that’s not super great. CancellationToken First, make use of the cancellation tokens.  I’ve talked about them … [Read more…]

Posted in: .NET Core, Asynchronous, C#, Concurrency Tagged: async, C#

Angular–Making a Modal Service by Extending NgbModal

January 11, 2019 by Robert 1 Comment

I like the idea of modal dialogs for certain things, especially showing error messages or confirming an action.  Creating (and styling) modal dialogs can vary so much that Angular doesn’t include them out of the box.  There’s a bunch of libraries out there that give you this functionality, including ones that are tied to a … [Read more…]

Posted in: Angular, Asynchronous, HTML, Typescript, Web Development Tagged: Angular, Blocking, Bootstrap, Dialog, Modal, NgBootstrap

Angular HttpClient unit testing

November 23, 2018 by Robert 2 Comments

There’s several tutorials for how to use and test HttpClient, but I wanted to distill it down to a simple snippet that I can refer back to when I inevitably forget how to do it. via GIPHY HttpTestingController This handy thing is provided by importing the HttpClientTestingModule in to your TestBed.  It lets you manipulate … [Read more…]

Posted in: Angular, Asynchronous, Jasmine, Typescript, Unit Testing, Web API, Web Development Tagged: Angular, HttpClient, Mock, Testing, unit testing

Adding a CancellationToken to TcpListener.AcceptTcpClientAsync

November 9, 2018 by Robert 7 Comments

A TcpListener opens a socket using TCP to listen for incoming connection requests.  You can use AcceptTcpClientAsync to asynchronously get a TcpClient object, which you can then use to send and receive messages on the connection. AcceptTcpClientAsync Waits forever to get a connection.  This is pretty much what you want most of the time… after … [Read more…]

Posted in: .NET Core, Asynchronous, C# Tagged: async, await, C#, Cancel, CancellationToken, TcpListener

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

Angular–Creating hooks to window events

September 28, 2018 by Robert Leave a Comment

Recently I had an Angular component that needed to be manually sized based on the window’s size.  Admittedly, this is pretty annoying, but the user experience was so much better than anything I could come up with using straight CSS.  It worked fine to get the dimensions of the window and calculate the width and … [Read more…]

Posted in: Angular, Asynchronous, JavaScript, Typescript, Web Development Tagged: Angular, Emit, Event, Hook, Observable, rxjs, Subject, Window

Jasmine–Setting the clock and deferring assertions

September 21, 2018 by Robert Leave a Comment

Sometimes when you’re writing Javascript unit tests you have to give Javascript a chance to catch up before checking your assertions.  Javascript uses a single event loop, so it isn’t multi-threaded in the same way as other languages.  You can still get a “multi-threaded feel” by using callbacks (promises, observables, etc), but at the end … [Read more…]

Posted in: Asynchronous, Jasmine, JavaScript, Typescript, Unit Testing, Web Development Tagged: Asynchronous, Jasmine, JavaScript, Testing, Typescript, unit testing

Jasmine–Testing code that contains setTimeout

September 14, 2018 by Robert Leave a Comment

Recently I wrote some code that contained a setTimeout.  The reason was so that the UI could catch up before the function actually fired – something that I’ve found the need to do with javascript from time to time. So, when it comes to testing the code… my test just skipped along until it literally … [Read more…]

Posted in: Angular, Asynchronous, Concurrency, Jasmine, JavaScript, Typescript, Unit Testing, Web Development Tagged: Angular, async, Jasmine, setTimeout, Testing, Typescript, unit testing

C# and Mongo–FindOneAndUpdateAsync

August 31, 2018 by Robert Leave a Comment

Recently I’ve been working on adding SignalR to a web application, and that means broadcasting records to clients after they’ve been updated.  I could make different methods for each update type and react accordingly, but I’m pretty lazy so I decided to just make one “update” method that receives the entire record (and replaces it … [Read more…]

Posted in: .NET Core, Asynchronous, C#, Mongo Tagged: C#, Database, Document, FindOneAndUpdateAsync, Mongo, Record, UpdateOneAsync
1 2 Next »

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