Thoughts on Software

# Tag: C#

• ## Image Manipulation, Streams and Denial of Service

So, you have some type of application that does simple image manipulation – in most web applications case, resizing. You use some library, you construct an object with the image binary as a stream, and it does some wizardry magic and poof, you’ve just resized the image and stored it in a file in an image format of your choosing.

But wait – some image formats aren’t that trivial. Maybe we don’t care too much about the detail of how it does this, but we do care about what happens to our streams, how it’s used, and how much memory is consumed – after all, we wouldn’t want our application to crash or become unresponsive, right?

• ## Concurrency with HttpClient

I’ve recently been heavily involved in moving towards a Service Oriented Architecture – and the most common form of Transport / Network Protocol used is of course, HTTP due to tooling and statelessness.

HttpClient is well known for being thread safe. Infact, it is very much encouraged to instantiate a HttpClient object and keep it in memory for as long as you need, this avoids the extra cost needed for reconstructing the object.

But, is it really that thread safe? Well, after some experiments with high volume of requests, it turns out – not completely / it depends.

if possible, I try to keep nesting of blocks to a minimum. In C#, there’s actually a good way of reducing nesting when combining using with the try catch finally within it.