Being Cellfish

Stuff I wished I've found in some blog (and sometimes did)

Browse by Tags

Tagged Content List
  • Blog Post: Collection initializers not doing what you expect

    Let's assume that you have a class that have a collection property and that you want the default for that collection to be to actually have a value. That class might look like this: 1: class Foo 2: { 3: public Foo() 4: { 5: this .Numbers = new List< int > { 4711 }; 6: } 7: public...
  • Blog Post: Task-based Asynchronous Pattern - kick starter

    Regardless of if you are new to TAP (Task-based Asynchronous Pattern aka " async/await ") or have been doing it for a while this presentation from an MVP summit in February (2013) serves both as a good introduction explaining how it works as well as providing deeper knowledge and high-lighting a few...
  • Blog Post: How to know when the garbage collector is not helping you

    A while back I did an experiment where it turned out that allocating objects was better than pooling them. Since then I have encountered a few times where allocating actually turned out to be a bad thing. I've never seen this being a problem in a client application, but in servers allocating a lot of...
  • Blog Post: Factory pattern improved

    My impression of most major west coast cities like Seattle, San Francisco, Los Angeles etc, is that people in general are very healthy. And Redmond where Microsoft have its HQ is even the bicycle capital of the north west (I guess anything can be the capital of anything if you just constrain geography...
  • Blog Post: Implementing a good GetHashCode

    If you've ever implemented GetHashCode you probably did it the way suggested in MSDN which is using XOR. And if you use R# you might have seen that it generates a different GetHashCode using prime numbers. So what should you do? I think there are three properties you want to aim for when it comes to...
  • Blog Post: Implementing IDisposable

    The IDisposable is probably one of the most abused interfaces in .Net. Except from all the cases where you actually have an unmanaged resource you need to release I've seen it being used a lot of times (including by myself) just to guarantee some code is executed immediatly when a variable go out of...
  • Blog Post: Task-based Asynchronous Pattern - PauseToken and common problems

    I just wanted to make sure you did not miss this article describing a mechanism to pause asynchronous processing. Just like the article state that this came out of a problem encountered in the UI World I think this is something I would not expect to see a lot outside the UI world. But it could be used...
  • Blog Post: Reactive Extensions Reminder

    It's been a while since I last looked at Rx and I must confess that my first impression was that the amount of possibilities to do the same thing and all the extension methods was overwhelming at start. But like with any new framework you learn you'll settle for a few to solve your most common problems...
  • Blog Post: TestInitialize execution order

    This was brought to my attention and I was blown away by the fact that somebody would mark classes as TestClass without any tests in them just to reuse some setup code. And that they then make any assumptions on in which order the methods are called. If you really want to do that the constructor is a...
  • Blog Post: Task-based Asynchronous Pattern - WaitAsync

    Recently I was asked about a specific scenario when some code was being converted into using TAP and this was code that already used tasks. Since the existing code used the "IsFaulted" property a lot I came up with this little extension method making it easy to see if a task failed or not using the await...
  • Blog Post: Type casting with extension methods

    Once in a while I need to convert one object from one type to another because they represent slightly different views of the same data but they do not share a common parent. An example would be an object used internally representing some complex state for something (let us call it FooComplex) and someting...
  • Blog Post: Task-based Asynchronous Pattern - WhenRandom

    I couldn't resist to create a method to deal with a scenario even less common than WhenSome . The crazy scenario here is that you have N tasks of type Task<T> and you want to return when a random task completes. The easiest way to do this is to just pick a random task and wait for it like this...
  • Blog Post: The tale of an UnobservedTaskException

    Last week I helped a colleague who was experiencing UnobservedTaskExceptions I his code. The problem was essentially that the code started several tasks and then in a loop checked each one if it was faulted or not. If a task was faulted the method threw an exception. This meant that if two tasks faulted...
  • Blog Post: Task-based Asynchronous Pattern - WithCancellation again!

    Last week Stephen Toub covered WithCancellation in a more thorough way than I did . You should read his article too!
  • Blog Post: Task-based Asynchronous Pattern - WhenAllOrErrorBatched

    This is a variant of WhenAllorError that a colleague asked me about. His scenario was that he had a lot of tasks to complete but since they all involved making HTTP requests to other servers he did not want to start them all at once but rather start a few and then as they completed start a few more....
  • Blog Post: Task-based Asynchronous Pattern - WhenSome

    I don't think this is the most common case, but sometimes you have a large number of tasks and you're interested in the result from a few of them, but not all of them. Here are some extension methods to wait for some tasks (no pun intended): 1: public static Task WhenSome( int target, params Task...
  • Blog Post: Task-based Asynchronous Pattern - WhenAllOrError

    A very common scenario when you scatter and gather, i.e. start a number or parallell tasks and then wait for them all, is that you really just want to wait for all if they all succeed. in the case there is an error you typically want to wait no more, handle the error, cancel any tasks not already completed...
  • Blog Post: Task-based Asynchronous Pattern - WithCancellation

    if you're working with a Task based API that does not follow the TAP rules and hence does not expose an option to cancel you can always add your own this way: 1: public static Task<T> WithCancellation<T>( 2: this Task<T> task, 3: CancellationToken cancellationToken) 4:...
  • Blog Post: Task-based Asynchronous Pattern - WithTimeout

    The same way we in CCR sometimes wanted to add a timeout to an existing "task" you probably want to do the same in TAP . So here are two extension methods you could use to add a timeout to any task of your choice: 1: public async static Task WithTimeout( this Task task, TimeSpan timeout) 2: { ...
  • Blog Post: Task-based Asynchronous Pattern - Introduction

    With .Net 4.5 and async / await we have yet another pattern for asynchronous programming and it's time for you to really embrace this. The pattern is called Task-based Asynchronous Pattern , or TAP for short. in my opinion a good asynchronous pattern makes asynchronous code look synchronous. i think...
  • Blog Post: Adopt a chaos monkey

    Remember the Netflix Chaos Monkey ? Last week they released the source code for it . maybe we'll see a port to .Net and Azure on codeplex soon?
  • Blog Post: ShimNotSupportedException when using ReSharper unit test runner

    I recently did some work using the VS 2012 RC together with R# 7 . I needed to use the shim functionality from Fakes but ran into trouble. My unit test failed with a ShimNotSupportedException. After a little bit of searching I realized it was because I was using the R# unit test runner (since it's much...
  • Blog Post: Working with threads

    I co-worker of mine stumbled over a nice collection of helpful information when working with threads in C# . Once you start using .net 4.5 with its async/await patterns you might be using multi-threading more than before and it's good to understand the basics.
  • Blog Post: Adding a timout to a task

    Remember how I added a timeout to an existing Choice in CCR ? Well with the new Task based world in .Net 4.5 you will probably want to do the same thing with a task returned by somebody else. Good for me this time is that somebody else already figured out how to do it . I especially like the approach...
  • Blog Post: Object pooling vs creating lots of them

    If you, like me, have a background in C programming it's a spine reaction to avoid lots of memory allocations. So when you encounter a situation in managed code where you need to allocate lots of objects over time it feels natural to introduce a pool of objects. However I remembered reading somewhere...
Page 1 of 3 (59 items) 123