Task.Delay Challenge

Friday, April 14, 2017

Task.Delay Challenge Task.Delay can be useful in many scenarios, for example: periodic execution.  Traditionally periodic execution done by using Timer API. Periodic execution with Task.Delay is easy for debug and better for maintain. The following code show the pattern: Code Snippet private async Task PeriodicJobAsync(CancellationToken token) {     var duration = TimeSpan.FromSeconds(5);     while (!token.IsCancellationRequested)     {         try         {             await Task.Delay(duration, token);         }         catch (OperationCanceledException) { }           // Process the job     } } The problem start when you want to test the code without waiting the real-world duration.   The challenge...
no comments

SDP Teaser

Tuesday, April 4, 2017

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...

Service Fabric Concept, Guidelines and Patterns #6-Deadlock

Saturday, February 20, 2016

Service Fabric Concept, Guidelines and Patterns #6-Deadlock this post is part of the Service Fabric’s series which covers Service Fabric’s concept, guidelines and common patterns. at this post we will discuss potential deadlock and good practice for avoiding it.   The idea for this post came while speaking with Jeffrey Richter from the Service Fabric team. When would you get deadlock on Service Fabric’s Actor Model? deadlock occurs when Actor A calls instance of Actor B and different call for Actor B (not recurrent) call the same instance of Actor A. A ---->...

Service Fabric Concept, Guidelines and Patterns #5–Map Reduce

Thursday, January 21, 2016

Service Fabric Concept, Guidelines and Patterns #5–Map Reduce this post is part of the Service Fabric’s series which covers Service Fabric’s concept, guidelines and common patterns. at this post we will discuss the Map Reduce pattern. quite like the Fork Join pattern Map Reduce is splitting a work into sub processing units, each handling portion of the overall processing. the difference is that Map Reduce sub processes produce the result in form of Key/Value pairs,while the reduction merge similar keys produced by the sub processing units,into single key value pairs (with no...

Service Fabric Concept, Guidelines and Patterns #4 – Fork Join

Service Fabric Concept, Guidelines and Patterns #4 – Fork Join this post is part of the Service Fabric’s series which covers Service Fabric’s concept, guidelines and common patterns. at this post we will discuss the Fork Join pattern. Fork Join pattern divide a work into sub unit which execute in parallel, the parallel results collected back into single result (PLINQ is classic sample for this pattern).   the following diagram describe the pattern.   when using the Actor model over Service Fabric, Actor Id dictate the actual instantiation. in...

Service Fabric Concept, Guidelines and Patterns #3 – Pool

Friday, December 25, 2015

Service Fabric Concept, Guidelines and Patterns #3 – Pool this post is part of the Service Fabric’s series which covers Service Fabric’s concept, guidelines and common patterns. at this post we will discuss the Pool pattern. there are many reasons for using pools, you may need a set of initialized resources, for boosting performance, limit memory allocations or limiting of concurrent access to resource (like connection string).  not matter what motivation you have, the pattern is quite simple to implement while using the Service Fabric Actor model.   remember that the Service Fabric’s...
no comments

Service Fabric Concept, Guidelines and Patterns #2 – Singleton

Tuesday, December 22, 2015

Service Fabric Concept, Guidelines and Patterns #2 – Singleton this post is part of the Service Fabric’s series which covers Service Fabric’s concept, guidelines and common patterns. at this post we will discuss the Singleton pattern. when using the Actor model, Service Fabric’s ActorId is the key component for implementation of most pattern when the Service Fabric resolve Actor instantiation it’s using ActorId for returning existing Actor or creating new one. for example: (Update the sample was wrong idx wasn’t “A”) var idA = new ActorId("A");var idB = new ActorId("B");var...