Andrew Arnott

News from my corner of the Visual Studio Connected Experience team, programming tips, and solutions to common programming issues.

TaskSchedulers and semaphores

When you write multi-threaded code, it’s important to be aware of whether the code in other libraries you call into is also thread-safe. By my observation, most code written is not thread-safe. So if you’re writing thread-safe code, kudos to you. But as you’ll sometimes need to call non-thread-safe code from your multi-threaded code, this… Read more

When TPL Task continuations are inlined

Task and Task in .NET 4.0 are absolutely awesome types and they provide the basis for async support that came in .NET 4.5. One somewhat unexpected behavior they have that can occasionally cause bugs in your code is that when a Task completes, it can execute continuations inline. In this post, I explain this and… Read more

Install Android SDKs using Powershell

The Android SDK Manager requires a GUI and tedious searching for the SDKs that you want to install. There is a command line android.bat script that lets you install and uninstall these without the GUI but it’s based on an ordinal index for each SDK so you have to run the script once, note the index(es) of… Read more

ImmutableObjectGraph has some big updates now, and more coming soon

I was able to work out a model for continued open source development of ImmutableObjectGraph — at least in a limited way. This means that the 16 month silence on the public repo is over, and I was able to push a bunch of the commits I had been keeping internal to the public. For… Read more

So many exceptions… but only one can throw

When a method may throw for more than one reason, the thoughtful programmer might ask “which exception should be thrown?” Consider a method which performs argument validation, is cancelable, and also might throw based on the state of the object. What order should these validations occur so that the best exception is thrown? Here is… Read more

Asynchronous and multithreaded programming within VS using the JoinableTaskFactory

Everyone appreciates a fast and responsive UI, and Visual Studio is no exception. Extensions that run in Visual Studio play a significant role in how responsive the IDE will be for its users. Visual Studio has been evolving over the past few cycles to not only improve performance, but also responsiveness during operations that may… Read more

Recommended patterns for CancellationToken

Whether you’re doing async work or not, accepting a CancellationToken as a parameter to your method is a great pattern for allowing your caller to express lost interest in the result. Supporting cancelable operations comes with a little bit of extra responsibility on your part. Know when you’ve passed the point of no cancellation. Don’t cancel… Read more

Immutable Object Graph updates

In my last post, I introduced a T4 template that constructs efficient and quite capable immutable objects based on the simplest mutable type definition. I also mentioned that the published sample is (necessarily, ala T4 style) open source and hosted online. Two outsiders have already submitted pull requests that have been accepted. Some thoughtful feedback… Read more

Simple immutable objects

We’re all familiar with immutable collections now. But immutability is only as immutable as it is deep. And an immutable collection of mutable objects may not provide the depth you’re looking for. So how can one create an immutable object? Suppose you would define the mutable version like this: public class Fruit { public string… Read more

Immutable collection algorithmic complexity

I received some feedback from my recent BCL blog post on the prerelease of the immutable collections that my algorithm complexity table left a few important entries out. Here is the table again, with more data filled in (particularly around list indexer lookup and enumeration):   Mutable (amortized) Mutable (worst case) Immutable Stack.Push O(1) O(n)… Read more