Summary of Microsoft Community Tech Days - 28th November Kolkata

Yesterday(28th November 2010), we had our Session for Community Tech Days Kolkata, In association with Kolkata .NET community we have put our effort to produce few great Sessions from few great people. In this post, lets cherish those magical moments we had together (or if you missed).  Here is the Agenda :


Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Debugging with Async

C# async feature really exposes a lots of things to us. I can see, there is lots of people is discussing about it in MSDN forums, few people wanted to get rid of the Task from the async methods and really want to deal with normal return types, while others just wanted to get rid of the async postfix. During my leisure, I read them but what I thought the most important part of the feedback is that most of the people really liked the way Microsoft simplifies the Asynchronous approach of programming style. 

I have already studied some of the important facts on Async style of programming, and found that it uses the StateMachine to let the program return after a certain portion of the method gets executed while the Rest of the program is sent as ContinueWith for the Task. Thus the TaskCompletion automatically restarts the method and continue. If you want to know more about how Task gets executed in async methods, please read my article where I have discussed how exactly the current trend of programming style got changed.

Today while I was looking at the implementation of Async style of programming, I just discovered an Internal class named DebugInfo inside the System.Runtime.CompilerServices.AsyncMethodBuilder.


You can see the class is internal, and hence not exposed from the perspective of BCL. You cannot create object of the class or even look at the private member LocationForDebuggerDisplay. But the only thing that you can see through this is the ActiveMethods.

Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Microsoft Community Tech Days - 28th November

Microsoft is going to arrange a Community Technical Day for us on 28th November 2010 here in Kolkata. The whole thing is organized by Kolkata Dotnet Community. I am very glad to announce that I am going to present Ribbon UI control for the seminar.



I will mainly present Windows Presentation Foundation in light of a new Ribbon UI Controlset introduced recently and may be added to the main line library in next version of WPF. Be there, if you wish.

To Register :

Register Yourself

Who else is speaking?

Abu Sayed Mohammad Ismail, Sankarsan Bose, Rajiv Popat, Abhijit Jana

See you there.
Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

C# 5.0 vNext - Asynchrony in Synchronous flow style code

There is a buzz all around on the new way of doing asynchronous programming using async database modifier and await contextual keyword. Threading or Asynchronous style of programming is very useful at times but each of us faced a lots of problems though converting a Synchronous code to Asynchronous coding style. Asynchronous style of coding is not new to the framework. From the very beginning of the evolution of C# as a language we can do programs that may run in parallel. But was it simple enough? No ! Its not. The way of writing our very own asynchronous programs can be very complex at times when we are about to deal with exception handling. We could have lots of callbacks around for every single asynchronous calls, there might be few thread blocks around for network calls etc.

C# 5.0 takes this into consideration and orchestrate the style of coding to more like synchronous manner.


I have already introduced, the two new keywords async and await which was introduced with async CTP recently, but it was just a rough introduction to the fact (as I posted that on the same day). Now let me move a bit further in this world and go with more complete asynchronous style of coding.

I have put a lovely article for you in codeproject with few sample codes. Please try the link below to read the whole story around async and await :

C# 5.0 vNext - New Asynchronous Pattern

You can also download sample Code from

Sample-CodeAsync - 385KB

I hope you would like this article. Please give your comments and feedbacks.

Thank you.
Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Reflection - Slow or Fast? Demonstration with Solutions

Many of you might have heard, calling reflection APIs from your code is always slower than that of calling it directly.  Well, it is right. Some of the major Reflection methods like GetXXX (of MethodInfo, PropertyInfo, FieldInfo etc) are say 100 times slower than that of calling a Method, Property or Fields directly. In this post, I will try to cover some of the major portion of Reflection which is slower like hell than that of normal method call and also try to solve the same.


So what is Reflection for?

As I have already told you about Reflection and Code Emit and also how to build your Lamda Expression Tree, it is good to know where you would like to use Reflection. Yes... Reflection is made truly late bound approach to browse through the object hierarchy or to call methods inside the object. So if you do not know much about your object hierarchy or you have somehow found an assembly external to your application and you need to parse through the object and call its methods say, then Reflection would be the right choice for you.

So basically Reflection allows you to create plugin type of applications where you define an Interface and publish the same for your application and let others create those plugins for you to seamlessly added to your application. Fine. Then what it isn't for?

Yes basically few people try to work everything based on Reflection. Using reflection unnecessarily will let your application very costly. Say for instance,

ConstructorInfo cinfo= typeof(MyType).GetConstructor(new Type[] { typeof(int), typeof(string) });
object createdObject = cinfo.Invoke(new object[] { 10, "Abhishek" });
MyType xyz = createdObject as MyType;

Or say using
MyType typ = Activator.CreateInstance<MyType>();

Silly huh..
I saw few people to do this. They try to use everything using Reflection, may be they love the Reflection too much, or they have already created a Reflection engine right and do not want to mix up unknown types with known ones. May be they would make their code clear by calling the known types to the same module that is built up for dealing with unknown types.

Download Sample - 60 KB

Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Rate your calls: Type Constraint Or Type Evaluation

You must be thinking why I am coming with such a strange Tag line today. Actually if you go on reading you would definitely understand what I am speaking on. In my last post, I have pointed out that Tuple is implemented in a strange way. If you see the 8th implementation of Tuple class, the one with 8 generic parameters, you will see, it gives a restriction to the last parameter TRest to allow only Tuple.

But the strange thing is, the restriction is not open. The Tuple class does not have this restriction specified in its generic type parameter TRest. So you can even declare the last argument as string, but when your application actually tries to create an object of it, the application will throw an ArgumentException.

This seemed to be very weird to me. I was thinking why did Microsoft did not put this in Type argument, making ITuple (an internal implementation) public, or create a special sealed class, and expose the same as a constraint to Type argument. I think this could be answered only by BCL Team.

Download Sample Code - 30KB

Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Working with Tuple in C# 4.0

After writing about C# 5.0, you might think why I moved a step behind with C# 4.0. Hey, I will definitely keep my promise to write a good  blog on new async and await feature, but because of time it is taking a bit time to go on. C# 4.0 being officially released contains lots of thoughts and approaches that comes handy in many places. There are lots of new features introduced with C# 4.0 where a few of them are really very handy.

Today, I will write about a very handy object introduced in FCL named Tuple which can store n - number of values in it.  Yes, you specify the type of each of those variables as generic parameters, and the object will create those values for you. Lets see how it works.

Using a Tuple


Base class library exposes two objects. It exposes the static class Tuple which allows you to get a number of Tuple instances based on the Static method Create, and a number of Tuple classes, each of which takes some specific number of Generic arguments.
  • Tuple.Create<t1>
  • Tuple.Create<t1,t2>
  • Tuple.Create<t1,t2,t3>
  • Tuple.Create<t1,t2,t3,t4>
  • Tuple.Create<t1,t2,t3,t4,t5>
  • Tuple.Create<t1,t2,t3,t4,t5,t6>
  • Tuple.Create<t1,t2,t3,t4,t5,t6,t7>
  • Tuple.Create<t1,t2,t3,t4,t5,t6,t7,t8>
Tuple.Create has 8 overloads and each of these overloads returns new object of Tuple<t1, t2...t8> class.  So .NET framework exposes 8 different classes each of them taking T1..... T8 number of arguments and each of them exposes Item1..... Item8 number of arguments.

Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Author's new book

Abhishek authored one of the best selling book of .NET. It covers ASP.NET, WPF, Windows 8, Threading, Memory Management, Internals, Visual Studio, HTML5, JQuery and many more...
Grab it now !!!