2018/05/13

I shift my posts from this blog to Medium.
I will still post a reference to my new post written at Medium.
Today I wrote about Span<T>.
You can check it at https://medium.com/@bnayae/net-span-t-better-performance-29b182b19dce
And you can find all other posts at https://medium.com/@bnayae/

2017/04/21

Task.Delay Challenge Solution This post suggest solution to the Task.Delay challenge. If you haven’t read the Task.Delay challenge you can find it here. In nutshell the challenge was about making Task.Delay like functionality which is test-able (using IScheduler for having virtual time). In order to support virtual time I will use Rx’s stream (which is also awaitable). The original Task.Delay is actually having 2 different completion path: - Complete by time. - Complete as result of cancellation token event. The general idea of the solution is to have 2 Rx’s streams one for each completion path: - Timer...

2017/04/04

This is a short teaser for what I’m planning to talk about in the next upcoming SDP conference. If you happened to be in Israel on May 2017 you can still register to the talk. The audience for this session expected to have prior knowledge about TPL, async / await and parallel programming in general. On this full day workshop I will focus on the less familiar aspects and patterns. Beyond Async And Await Planed Agenda * Task from different angle * Task.Run vs Task.Factory.StartNew * async / await drill down and custom awaitable * Some...

2017/03/15

Async Tip: why you should avoid void The guideline to prefer async method which return Task over async method that return void is quite known, but why should you follow the guideline? Code Snippet public async void NotRecomendedAsync() { // do something await SomeCodeWhichMayThrowAsync(); // do something } public async Task RecomendedAsync() { // do something await SomeCodeWhichMayThrowAsync(); // do something } The first obvious reason to use the guideline is testability. When you return void the test don’t really know when it is right time to check...

2017/01/26

Task.Run vs. Task.Factory.StartNew (Part 2) This post continue the previous post about the differences between Task.Run vs. Task.Factory,StartNew. In the previous part I was speaking about the scheduling aspect, on this part I will spot the async await behavior. Check the following code snippet and think what can go wrong: Code Snippet private async Task ExecuteAsync() { var sw = Stopwatch.StartNew(); await Task.Factory.StartNew(async () => { Console.WriteLine("Start section"); await Task.Delay(1000); Console.WriteLine("End section"); }); Console.WriteLine(sw.Elapsed); } What output will it produce? Will it be something like the following output: ...

2017/01/24

Task.Run vs. Task.Factory.StartNew (Part 1) This post will focus on the key difference between Task.Run and Task.Factory.StartNew. For you can drill down into more details on this excellent post by Stephen Toub. In general you have to know that Task.Run is more restricted version of Task.Factory.StartNew. Task.Run sets default which fit for most common cases. Task.Factory.StartNew is there for advance scenarios. in general Task.Run is equivalent to: Code Snippet Task.Factory.StartNew(someAction, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); Why should you care about it and how can it be used right?...