HttpClient.SendAsync using the thread-pool instead of async IO?

this.startRequest is a delegate that points to StartRequest which in turn uses HttpWebRequest.BeginGetResponse to start async IO. HttpClient is using async IO under the covers, just wrapped in a thread-pool Task. That said, note the following comment in SendAsync // BeginGetResponse/BeginGetRequestStream have a lot of setup work to do before becoming async // (proxy, dns, … Read more

Load javascript async, then check DOM loaded before executing callback

What you need is a simple queue of onload functions. Also please avoid browser sniffing as it is unstable and not future proof. For full source code see the [Demo] var onload_queue = []; var dom_loaded = false; function loadScriptAsync(src, callback) { var script = document.createElement(‘script’); script.type = “text/javascript”; script.async = true; script.src = src; … Read more

Sessions in Asynchronous design

Thanks to everyone that posted answers and comments to my question. I’m summing up my findings and solution so that someone may find this useful. Everyone that commented is correct about recommending not to use Sessions in asynchronous calls. So, how did I get around it? Changed PageMethod call into a HttpHandler implementing IReadOnlySessionState. (In … Read more

Pause and Resume Subscription on cold IObservable

Here’s a reasonably simple Rx way to do what you want. I’ve created an extension method called Pausable that takes a source observable and a second observable of boolean that pauses or resumes the observable. public static IObservable<T> Pausable<T>( this IObservable<T> source, IObservable<bool> pauser) { return Observable.Create<T>(o => { var paused = new SerialDisposable(); var … Read more

C# Async Serial Port Read

Use async programming (don’t forget to target first your application to .NET Framework 4.5). Here you’ve my implementation as extension methods for SerialPort. using System; using System.IO.Ports; using System.Threading.Tasks; namespace ExtensionMethods.SerialPort { public static class SerialPortExtensions { public async static Task ReadAsync(this SerialPort serialPort, byte[] buffer, int offset, int count) { var bytesToRead = count; … Read more

Dns.BeginGetHost… methods blocking

System.Net.Dns uses the windows gethostbyname function for DNS queries and doesn’t really have asynchronous functions at all. The BeginGetHostEntry function is basically just a wrapper for a synchronous GetHostEntry invocation on the thread pool. Last time I had this same problem with slow/synchronous DNS lookups I eventually just used a large ThreadPool to get the … Read more