Tpl Dataflow walkthrough – Part 5

2012/01/28

Tpl Dataflow walkthrough - Part 5 this post is a complete walkthrough of a web crawler sample that was build purely by using Tpl Dataflow. it was built on .NET 4.5 / C# 5 (on a virtual machine using VS 11). I will analyze each part of this sample, both by discussing the Dataflow blocks and the patterns in used. the sample code is available in here (it is a VS 11 project). during the walkthrough you will see the following Tpl Dataflow blocks: TransformBlock ...

Rx – Aggregate vs. Scan

2012/01/24

Rx - Aggregate vs. Scan this post will focus on 2 Rx operators Aggregate and Scan. both Aggregate and Scan are dealing with event stream accumulation, the only difference is that Aggregate produce single result (upon the stream completion) and Scan present an ongoing runtime accumulation which react for each OnNext. both operators has 2 overloads with the same signature: Code Snippet IObservable<TSource> Aggregate<TSource>(     this IObservable<TSource> source,     Func<TSource, TSource, TSource> accumulator);   IObservable<TSource> Scan<TSource>(     this IObservable<TSource> source,     Func<TSource, TSource, TSource> accumulator);   IObservable<TAccumulate>...

Rx – Exception Handling

2012/01/22

Rx - Exception Handling this post will discuss exception handling within the Rx arena. handling event stream exception is not trivial, for example observable should delegate exception to its subscribers though the OnError operation and cancel the subscription. on the other hand the subscriber may want to response OnError state by renewing its subscription or fallback to alternative stream. it is true that the Rx design guidelines suggest that faulted stream should not continue to produce data, but real-world implementation such as stuck...

async / await, some reasoning

2012/01/19

async / await, some reasoning this post will try to make some reasoning about the .NET 4.5 / C#5 await keyword. I will begin with a quiz. how long will it take to the following method to produce the 42 value? Code Snippet async Task<int> Execute() {     await Task.Delay(1000);     await Task.Delay(1000);     return 42; } you should remember that conceptually the await keyword will translate to a continuation. the above code can be compare to the following TPL 4 code snippet: ...
no comments

Using async / await

2012/01/15

Using async / await this post will discuss parallel disposal. whenever we want to dispose a parallel execution upon completion we can't use the convenient using keyword. for example, the following code may be dispose the command before completion: Very bad Code Snippet using (var conn = new SqlConnection(CONN_STR)) using (var cmd = new SqlCommand("Select * from Employee", conn)) {     conn.Open();     cmd.BeginExecuteReader(ar =>         {             int affected = cmd.EndExecuteNonQuery(ar);         }); } the using is absolutely wrong for the above sample. what should be...

async \ await and Exception Handling

2012/01/12

async \ await and Exception Handling this post will discuss how async / await is handling exceptions. as we mention in previous post, about the async / await concept, await is all about continuation. before .NET 4.5 parallel execution exceptions has to be handle in separate of the synchronic handling. for example: handling ThreadPool execution: Code Snippet void Foo() {     try     {         Console.WriteLine("Synchronic");         ThreadPool.QueueUserWorkItem(state =>             {                 try                 {                     Console.WriteLine("Parallel");                 }                 catch (Exception exAsync)                 {                     EventLog.WriteEntry("application", exAsync.ToString());                 }             }, null);     }     catch (Exception ex)     {         EventLog.WriteEntry("application", ex.ToString());...

Rx – Sample

2012/01/05

Rx - Sample this post will focus on the Rx Sample operator. the Sample operation does sampling the observable stream and forward less intensive data stream of the sampled datum. it can be prove very useful for scenario like handling accelerometer stream which can produce 60 value per second, in some cases we don't need such intensity and our machine resources may be happier to handle only 10 value per seconds. the same may be apply to video stream analytics and many other...