Daily DotNet Tips 1 year and onwards


We are excited to celebrate 1st Anniversary of our site DailyDotnetTips today. It aims to share useful programming tips for .net developers.This site completely design for sharing Tips and Tricks, useful Code Snippet which anyone use in daily development work and targeted anything related with .NET.

Here is some of the statistics : 

  1. Founded : 27th December 2010
  2. No of Posts : 250
  3. No facebook likes : 502
  4. No of participants : 7
  5. No of Twitter followers : 348

We are still a long way to go. Follow us and be a part of it. 

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

DEVCON – Kolkata, A New Beginning on 12th November, 2011

November 12th , we are getting together for a big event Developer Conference 2011 Organized by Microsoft User Group Kolkata (KolkataGeeks) .  Developer Conference is the premier technical event for technology professionals at Kolkata interested in learning, connecting and exploring latest Microsoft technologies.  This is also going to be community Launch event for Office 365. So be there and enjoy the flavor of cutting edge Microsoft technologies.
This is a full day event and you can attend this  event in person at Bharatiya Bhasha Parisad 36A, Shakespeare Sarani, 4th Floor  Kolkata – 700017.  Overall there are 7 different sessions which primarily focused on latest Microsoft Technologies.  .  Check the Dev Con Web Site for more information.
I’ll be presenting on “Windows 8 Metro Style Application“.  In this session I will talk about latest Windows release and how you can get best out of it through your Metro Style applications. There will be lots of demo in this session. 
Check out session details and agenda from here http://kolkatageeks.com/DevCon2011.aspx .  You can register for this event over here  http://kolkatageeks.com/DevCon2011/Register.aspx
See you there !
Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Layout adjustments Snapping and OrientationChanges in Metro Applications

If you have read my first article on Windows 8 metro styled application, you might already know about the working principle of it. I have talked about the capabilities for an application and settings which end user can configure for an application. In this post I will take a look at the basic layout structure that one needs to follow while creating an application in WinRT Metro styles so that it is best suited to perform well.

Layout is the most important part of any application. The best design for an application gets more credit and love from the users than applications that are designed bad. Metro style applications runs in full screen. Your application does not include a  Title Bar, status bar or anything. Microsoft gave us some of the basic layout guidelines that one needs to follow. Lets talk about them here to make you understand how you should layout your application in Metro Applications to utilize maximum flexibility of it.

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

Understanding basic WinRT Metro Applications and Application Capabilities

Just about a month ago, WinRT was introduced with all new style of application development that can work better with Multi Touch Enabled devices. We call it as Metro Applications. In this post, I will discuss how to develop your first metro applications and how to work with its layout changes.

How to Start

Before we start talking directly about Metro Style application, let us see how to install it first. I refer to use OracleVM which you can find for free from this link, and install.  This will install a Virtual Machine in which you can install the Developer Preview of Windows 8.

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

Regular Expressions with Timeout in .NET 4.5

.NET 4.5 Developer preview is out with Visual Studio 2011. I was already thinking to try out what's new in .NET 4.5 myself and share what exactly been changed.

Lets start by the new Regex Api introduced with the framework. The improvement that has been made is minor yet handy at certain cases. The Regex class of .NET 4.5 supports Timeout. Lets take a look how to work with it.

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

Generic Types and Static Members

One of my friend recently asked me a question that I think I should share with you. Say you have a Static Implementation of a Type T which you pass as Open Type in your Generic Class. Now the problem is how to get reference to the Static Members or invoke a method that is Static to the Type from the Open Type T.  In this post, I will demonstrate few implementations that help you getting the Static implementation.

First of all, According to C# documentation, any type allocates its static members once per Type rather than once per Open Type. Now lets define this using the code below :

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

Internals of .NET Objects and Use of SOS

Well, now getting deeper into the facts, lets talk about how objects are created in .NET and how type system is laid out in memory for this post in my Internals Series.  As this is going to be very deep dive post, I would recommend to read this only if you want to kill your time to know the internal details of .NET runtime and also you have considerable working experience with the CLR types and type system.

Recently I have been talking with somebody regarding the actual difference between the C++ type system and managed C# type system. I fact the CLR Type system is different from the former as any object (not a value type) is in memory contains a baggage of information when laid out in memory. This makes CLR objects considerable different from traditional C++ programs.

Classification of Types

In .NET there are mainly two kind of Types.
  1. Value Types (derived from System.ValueType)
  2. Reference  Type (derived directly from System.Object)
Even though ValueTypes are internally inherited from System.Object in its core, but CLR treats them very differently.  Indeed from your own perception the Value Types are actually allocated in stacks (occationally) while reference types are allocated in Heaps. This is to reduce the additional contension of GC heaps for Heap allocation, GC cycles, occasional call to OS for additional memory needs etc. The object that is allocated in managed Heap is called Managed Object and the pointer that is allocated in stack to refer to the actual object in heap is called Object Reference (which is sometimes called as Managed Pointer). 

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

Internals of Interface and its Implementation

As many of my followers requested me to write few things that I missed out from the Internals Series, I should continue with it. In this post, I will cover the internals of Interface implementation and mostly talk about explicit interface implementation, as most of the developers seems to be in confusion with it. I hope you will like the post.

Beginning from the basics, Interfaces are the most important part of any application. Interfaces are language construct that does not implement anything but declares a few members upfront. Generally we use interfaces to create a contract between the two or more communication agents. Another important thing that everyone would be knowing already, Interfaces are meant to be implemented. That means whenever you are creating a class, all the members that were there in the interface are meant to be implemented completely. .NET (or probable any other standard language) disallows the creation of objects on types that are not fully defined. Hence abstract classes also coming into play here. They are classes that have few members undefined or abstract. Once you don't have concrete implementation, you cannot create an instance of a type. Notably, you can say "Interface is a types that does not belong to the System.Object or implement it when it reside inside an assembly". But ironically you could also says that once the type is implemented, it would probably inherit from System.object by default.

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

Writing a Custom ConfigurationSection to handle a Collection

Configuration is one of the major thing that you need to keep in mind while building any application. Either its an Windows Forms application or a Web site, configuration file is always needed. We write all the configuration that are needed to be changed after it is being deployed in confugration files. It is an XML File which lists all the configuration blocks itself and also allows you to define your own custom configuration sections yourself. Today I am building my own custom configuration section and show how easily you can build yourself.

While dealing with Configurations, there are two things that you need to address

  1. ConfigurationSection
  2. ConfigurationElement
  3. ConfigurationElementCollection

For most of the simple configurations, it is pretty much common to use these two classes, but when you need more complex configuration block, like appsettings which actually puts a Collection of ConfigurationElements, you might need to use ConfigurationElementCollection to hold the collection of ConfigurationElement. 

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

31 Tips for the month on Threading, WPF, MEF, ASP.NET

Daily .NET Tips is aiming to sharing useful coding tips and tricks for .NET Developers. This site completely design for sharing Tips and Tricks, useful Code Snippet which anyone use in daily development work and targeted anything related with .NET.   This month we have wide range of tips including Threading, MEF, WPF and MVC. In this post I am quickly listing down all the tips which are published over the month August 2011. And the most important point to mention, among those 31 tips that has been posted on DailyDotnettips this month 22 is coming from me. 

  1. Working with AggregateCatalog in MEF
  2.  Working with DirectoryCatalog in MEF
  3. Working with AssemblyCatalog in MEF
  4. Working with TypeCatalog in MEF
  5. How to use DebuggerTypeProxy while debugging your sensitive Type
  6. ASP.NET Calendar Control as Outlook Calendar
  7. Initialize assemblies using PreApplicationStartMethod for ASP.NET 4.0 Application
  8. Async Lambda Expression
  9. Playing with ASP.NET List Controls using jQuery
  10. How to allow user to input html in ASP.NET MVC?
  11. Using Mutex to avoid deadlocks
  12. Writing inline Code in WPF
  13. What is SynchronizationContext all about
  14. ThreadLocal storage in .NET
  15. Barrier in .NET 4.0
  16. Use of Interlocked in Race Condition
  17. Call ASP.NET Page Methods using your own AJAX
  18. Use of SpinLock for ThreadLocking
  19. Using ReaderWriterLock over Monitor for Thread Locking
  20. What is the use of IsBackground property of Thread?
  21. Enable Address Level Debugging in Visual Studio
  22. Get List of all Control Types in WPF
  23. How to apply simple faded transparent effects on WPF controls ?
  24.  Use Visual Studio Server Explorer to Add New or Existing SQL Server CE Database
  25. Co-Ordinated Thread Shutdown with and without using CancellationTokenSource
  26. Generate thousand of request
  27. Writing a Stretchable ContentControl in WPF
  28. How to Retrieve WPF Visual Tree Programmatically ?
  29. What is Visual Tree and Logical Tree in WPF?
  30.  Dealing with HWND in WPF
  31. Hosting a WPF control inside a Windows Form
To get regular updates visit http://dailydotnettips.com and follow @dailydotnettips at Twitter.

I hope you would like the posts. Stay tune for more. 
Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

Monday Mornings : Extensibility in .NET 4.0

It is my great pleasure to speak at Microsoft Moday's last Monday on 22nd August 2011. I have introduced a way to develop a plugin based application with and without MEF. I have also touched some of the interfaces which Visual Studio uses for Extensibility. It has been a very good session and I have learned a lot from it.

If you are a part of the session, please get the Power Point Presentation and the updated source code.

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

Steps to write a plugin based application with MEF

I have already written a blog on Managed Extensibility Framework few days ago, and you must wonder why I am writing again. Well actually today I have been creating an application that could be easily plugged into a host application. In this blog lets show you in steps how you could easily create your own plugin based application and later change itself easily using MEF.

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

.NET Tips : List of my short tips

Hi Friends,

As I have already told you that I have been publishing short tips in DailyDotnetTips regularly, it is time to share the links with you to keep you updated. Please read these short tips from me and give your feedback.

  1. Using ReaderWriterLock over Monitor for Thread Locking
  2. What is the use of IsBackground property of Thread?
  3. Co-Ordinated Thread Shutdown with and without using CancellationTokenSource
  4. Writing a Stretchable ContentControl in WPF
  5. What is Visual Tree and Logical Tree in WPF?
  6. Dealing with HWND in WPF
  7. Hosting a WPF control inside a Windows Form
  8. Accessing local assemblies in XAML
  9. Difference between a UserControl and a CustomControl
  10. Hosting a Windows Forms control inside a WPF
  11. Use x:Shared to write your FrameworkElements directly as Resource
  12. Use BitmapScalingMode to ensure your rendering of Image is perfect
  13. Object hierarchy of NULL
  14. Lazy Initializer to defer expensive Object creation in .NET 4.0
  15. Working with Co-Variance and Contra-Variance in .NET 4.0
  16. Using Complex Numbers in .NET 4.0
  17. Working with BigInteger in .NET 4.0
  18. Working with SortedSet in .NET 4.0
  19. Common Table Expressions in SQL Server
  20. Compiler directive #Pragma reference

So here are my last 20 short tips posted on DailyDotnetTips

I hope you will like these tips. For full list of all the tips and the latest updates, check this link

Happy Coding. 

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

Internals of Dependency Property in WPF

WPF introduces new property system to us. Every WPF objects that is inherited from DependencyObject inherently supports Dependency property containers within it. That means you can define your own dependency property in your code which can take part in some of the interesting features of WPF like Binding, Styles, Triggers, Animation, Property Inheritence etc. Today I will concentrate on how Dependency Property system is actually built and what are the benefits we get instead of using CLR property system.

Note : If you are really new in WPF and don't know about Dependency Property, it would be nice to read my post on Dependency Property or you can also try WPF Tutorial series to start on.

So lets start on using the most basic code of creating your own Dependency Property.

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

Writing a Reusable Custom Control in WPF

In my previous post, I have already defined how you can inherit from an existing control and define your own reusable chunk. The reusable XAML code that I have defined there is actually a composition of one of more existing elements in a common design surface. But sometimes you must define  a new behaviour for your reusable component which does not belong to any of the already existing behaviors. Custom controls can help you in this. You can define a new behaviour for your Custom control which can have a default look and feel defined for it, and obviously which can be changed using Template for the user who is using the control. In this post I am going to provide you step by step approach on defining a Custom Control for your application.

Note: If you are really new to WPF, please read my WPF Tutorial before going further. 

Steps to Create a new Custom Control

Creating a custom control is very simple. Just in your project right click and add a new Item. In the dialog box that appears, choose Custom Control template and Name it. I call it here as SimpleControl.

Once you have added the control, it adds up a new class to your project which inherits from Control. The Template also provides you with some initial help to define your own control. Lets remove all the comments for now and start building a control.

Download Sample Code

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

Writing a Reusable WPF Control with Design Support

Code reusablity is one of the major concern to many of us. When dealing with large projects, modularizing your project is one of the primary thing that you should look for. I have talked about many of the approaches that you can use to deal with modularizing your code, eg, Prism. In this post our intent is not to talk hard on some pattern, rather I will discuss how your WPF application supports code reusability. There are a number of approaches that WPF supports to deal with reusable component. We can use Resources to define a Resource or even use CodeBehind to write our reusable component or even load the XAML from a file using XAML Loader. Each of the approaches has its own pros and cons. Today I will show you another cool technique to write a reusable XAML for your project which will allow you to easily use Visual Studio design surface to design the component.

Note : It is a very basic article, if you want to know about details on WPF, please read my tutorial on it.

Steps to Create your Reusable Component

Lets create a series of steps to create a reusable component for your application to make it easier for you to write one yourself.

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

ValueType and ReferenceType : Under the Hood Part 2

Well, if you have read my previous post, you should be already clear how memory of ValueTypes and ReferenceTypes are allocated and De-allocated internally in terms of IL. Here in this post, I am going to cover some more concepts behind ValueTypes and ReferenceTypes and what exactly comprises of them.

In my previous post on the series, I have told you that any type that inherits from System.ValueTypes is stored in Stack while any type that is not inherited from System.ValueType is stored in Heap. Well, the statement is not correct totally.

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

ValueTypes and ReferenceTypes : Under the Hood

In .NET, Value Type and Reference Types are forms an element of confusion between both developers and the students. Many of us take this as granted that Value Types are allocated in Thread Stack ( a 1 MB local stack created per Thread) and on each method calls the local value types are allocated in the Stack such that after the call ends, the object is deallocated. On the contrary, the reference types we know are those which are always allocated in heap (which is not always true, I will discuss later) and even though they are used as locals, and will be deallocated only after an interval by a separate Thread that is running with any .NET process (called finalizer thread) which occationally starts finding the memory blocks on Heap storage and compact and store only the reachable objects called Garbage Collector. Well, in this post, I am not going to cover the details of Garbage Collection, but rather I will focus more on Value Types and Reference Types that I know personally to clear any doubt regarding them in terms of IL constructs. So after reading the post, you will know some of the basics of IL too.

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

Rethinking my Session on TechEd on Road

Hi Folks,

Its been a great time together on TechEd on Road event here in Kolkata. I can recollect the fun we had out of the sessions with Pinal Dave, nice to find you here Pinal and with Bijoy Singhal on Windows Phone 7. I would also like to thank Dhanajay Kumar for coming all the way from Pune only for this session, and also for giving a wonderful session to us. 

Lets now talk about my session on ".NET Fundamentals that every developers should Know". In this post I will share all the resources and source codes to make your easy way round to understand everything that you didnt understand in the session,  of course if any... :) 

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

Managed Extensibility Framework - A Look

Hi guys,

If you are really new to .NET framework 4.0, this is going to be a quickstart guide to a new framework for extensibility which every developers should know. In this post, I will give you a brief introduction to what Managed Extensibility Framework is all about and also create a sample application on the same.

Note: This is the basic stripped version of MEF, if you are looking for something more advanced, stay tune with my blog; its about to follow. 

Why Managed Extensibility Framework?

You can say MEF is a framework that is built on top of Reflection API, that addresses one special kind of requirement that most of the current developers are in. Modularizing an application is one of  the biggest concern for any software giant. Everyone, like me, look for some sort of plugin based modularization for their respective application and ultimately end up doing in their own way like what I did before, which ultimately does not solve the problem as someone else might end up doing the same thing little differently and eventually "my plugins cannot go into your application" kind of situation. Hence we need some sort of standardization to  address this situation such that every plugin based application can work together. MEF addresses this situation by giving you a sleek way of defining your modules as plugins and your application as a Standard host of any plugins.

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

Some facts about Null in .NET

As I am tweeting around the facts on Nulls for last couple of days, I thought of writing a blog on that as many of you have already requested me on this regard. This post is basically dealing with Nulls and will go through only with basic C# stuffs, so for geeks, it is not recommended and you might end up knowing a little or almost nothing. So if you just here for time pass, then I refer to read on.

Considering the fact Nulls appear on any objects, we have mainly two categories of programmable storage in .NET.

  1. Nullables (generally mutable with exceptions like strings)
  2. Value Types / struct (generally immutable)
Nullables are types that either user defined or in framework in which one of its value can be null. .NET treats null specially. Say for instance :

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

Concept Overide vs Method Hiding in terms of C#

Overriding is one of the most interesting topic that many software professionals are dealing with quite regularly. Most of the applications we write in .NET or other languages somehow uses overriding. While you write your class, one of the most important thing that you need to consider is overriding ToString() to ensure that your class does not produce the “Name of the class” rather you produce something useful on your context. Method hiding is another concept similar to Overriding but is actually different in many respect. But I saw many people does have a little confusion among these two concepts and does not know when to use what. Here is some sample which would help you deal with these concepts easy.


Overriding means redefining an existing method that comes inherited from parent class. Say for instance, you have defined a class Animal. Animal can move and eat. So let’s define the class :

public class Animal
        public virtual void Walk()
            Console.WriteLine("Animal is now Walking");
        public void Eat()
            Console.WriteLine("Animal eats for living.");

So this is quite a simple class that provides two methods. The first one is Walk which prints a message, and another is Eat, which again prints another message. Now notice, I have made the Walk method of Animal Virtual. Virtual means, the method will be bound at runtime, hence no compile time binding will be produced and runtime object will take over compile time bindings.

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

Working With Prism 4.0 (Hello World Sample with MVVM)

Modularity is one of the primary concern when working with a big projects. Most of us think of how we can implement our application that could be reusable across more than one applications. Patterns and Practices Team puts forward the notion of modularity with the help of Unity and Prism which most importantly focus on WPF and Silverlight applications. Being a WPF developer, it would be nice to take this apart and explain you a bit of how you can implement your application using Prism.

Before you begin, I must tell you, this is the most basic article that guides you step by step how you can write your first Prism based application and what are the advantages of building such kind of application. I will take this further in my next posts to make more concrete samples. So if you know the basics of how you can work with Prism, I would recommend you to read my next posts.

Also I assume you have some knowledge of Unity, WPF and MVVM to get you through with Prism.

Where do I find Prism? 

Prism is a framework introduced by Patterns and Practices Team which is available from here. After you install your bits, you will get a folder named Prism on your local drive. After you are done, lets start coding.

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

Playing with Reflection and Async

Hi Guys,

Task Asynchronous Pattern as you already know from my article, is one of the major change of next generation .NET applications. As this is already discussed in detail in the article, I will not repeat the same again here in this post. If you don't know what is it, please go ahead and read the article. In this post, I will try to use reflection to invoke our own async method. 
So to start, let us take a look at one of the simplest Async method. 
static void Main(string[] args)
    Program p = new Program();

    Task t = p.TryCallAsync(10000);


public async Task TryCallAsync(int delay)
    Console.WriteLine("TaskEx.Delay is called : will wait for {0} milliseconds", delay);

    await TaskEx.Delay(delay);

    Console.WriteLine("Finished execution Return to the caller");

In this code I have just put a delay of 10 seconds. Now after the execution is finished, another message will be printed on the screen.

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

Internals of Array

Arrays are most important part of your program. Almost most of the collection that you work with in .NET framework is internally maintains Array. Say for instance, if you take the List it actually internally represents T[], while Dictionary is actually an array of structure KeyValuePair internally. Hence, array forms a very important part of your program. 

Few days back while browsing over internet when I found an article written one of my buddy Dhananjay Kumar here, I thought how could I forget this important section of C# language, hence in this post, I will cover some of the important things that you need to remember while you use arrays in .NET.

Arrays Vs IEnumerables

Well, when working with Collections, the first thing that will come in your mind is the IEnumerables. Well, IEnumerable is the generic implementation of any iterators. In .NET every array internally implements an IEnuerable. You may think IEnumerable as a iterable sequence, which could be applied to anything that is iterable while array on the other hand has a fixed set of values contiguously allocated. By the way, each arrays actually implements an IEnumerable internally, so eventually in .NET every array is by default an IEnumerable.

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

.NET Tips – Links on ASP.NET C# MVC Visual Studio Tips

Daily .NET Tips is aiming to sharing useful coding tips and tricks for .NET Developers. This site completely design for sharing Tips and Tricks, useful Code Snippet which anyone use in daily development work and targeted anything related with .NET.  In this post I am quickly listing down all the tips which are posted over the month May 2011.
To get regular updates visit http://dailydotnettips.com and follow @dailydotnettips at Twitter
Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

First day experience with MVP Open Days

After not being talked for long, you might be thinking what will be coming next as article. Well, there are still quite a few topics in mind and some of few I have already started working, and will  be soon be coming to my blog; but for  now I am now very much excited to share what is happening with me in Microsoft MVP Open days I am here in Hydrabad with you, and I am sure you will also enjoy reading it.

So if you only want to look for some technical ones, I would recommend you to select some other post on the website which are entirely suit you. If you are in a mood to relax, you can go on reading this post and enjoy.

What is MVP Open Days ?

Being an MVP is always a great achievelt to me. The first day I got the notification that I got MVP I wonder what would be the benefits that I will get after being an MVP. Being an MVP is not only one of the prestigious award that one can get working on Microsoft technologies, it is something more. You get special previledges from microsoft to get in touch with product teams, you get all the microsoft softwares for free and also you are invited to some of the global events that microsoft is organizing. Well, you can say MVP Open Days is one of such an event. In MVP open days we have been invited to take part of discussions on very recent ideas of what Microsoft is going to do (dont ask me about it as its under NDA) but also has a chance to networking with some of the peoples whom you would have admired from the early days of your career. Being a part of this elite group, I cannot miss this opportunity to come to hyderabad and move on with the event.
Shout it Submit this story to DotNetKicks Bookmark and Share
Read Disclaimer Notice

DLR in C# using Scripting Language

You should note, till now C# has very little Dynamic Language feature. As mentioned in PDC, we will soon have the feature Compiler as Service feature in C# it is really hard to wait for such a thing to happen. As for me, after the dynamic capabilities released with C# 4.0, I was really excited to look deep into it to find out what is possible. In my Internals series, I have already mentioned you some of the details of what is implemented inside of C# to achieve the Dynamic capabilities in the language. The introduction of ExpandoObject and DynamicObject classes and also with the Expression Trees gives an edge to dynamism in C# but still there is something missing in the language.  There is still something missing which will eval a script and return the result as every scripting engine does, like javascript.

Even though there is no comparison between javascript and C# as both are completely different, whereas the former is completely type unsafe and interpreted language while later being strongly typed language, still I want more from the language. One might think, we could dynamically compile the objects either using Reflection.Emit or Expression Trees and evaluate the statements using Reflection apis, but believe me, it is not the right way to go as the complexity will increase very fast.

For such a scenarios, where you dare to find some expression evaluator from C#, it is better to use some scripting languages which runs inside .NET environment, yet allows you to use DLR capabilities. One of such language is IronPython.

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

My 17 .NET Tips on Silverlight ASP.NET Windows Phone C# From DailyDotNetTips.com

Daily .NET Tips is aiming to sharing useful coding tips and tricks for .NET Developers. This site completely design for sharing Tips and Tricks, useful Code Snippet which anyone use in daily development work and targeted anything related with .NET. In the past few months I have share many tips over there, just giving quick link of them

BannerTips #1 : How to Customize On-Screen Keyboard Layout in Windows Phone 7 application ?

Tips #2 : How to use Application Bar in Windows Phone 7 Application ?

Tips #3 : AncestorType in RelativeSource – Silverlight 5

Tips #4 : RichTextBoxOverflow Control in SilverLight 5

Tips #5 : Binding in Style Setters – SilverLight 5 Beta

Tips #6 : Implicit DataTemplates for Control in Silverlight 5 Beta

Tips #7 : Collection Initializers in .NET

Tips #8 : Working with TypeDescriptor in C#

Tips #9 : Pixel Scrolling for WPF Lists

Tips #10 : Getting Lazy with .NET 4.0

Tips #11 : Annonymous objects in C#

Tips #12 : InputBinding for WPF and Silverlight with MVVM

Tips #13 : How to deal with CPU usage in WPF application ?

Tips #14 : Handoff Behavior in WPF Animation

Tips #15 : Lazy Load XAML content from External File and Vice Versa

Tips #16 : Publish Desktop Application – SmartClient

Tips #17 : Different approaches to Casting

You can find all my posts in the site from the following link :

To learn more .NET Tips Daily Visit http://dailydotnettips.com and Follow @DailyDotNetTips at Twitter

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

Creating Animated Splash screen in Windows Phone 7

Creating a beautiful splash screen is always great to see for any application. Windows Phone 7 being no exception to it, you want to give the user great look and feel while loading the application using your Splash Screens. In this article, I am going to spend some time by talking about some of the probable options that you have to create your own Splash Screen for your windows phone 7 application.

What is Splash Screen?

Splash screen is the first screen that comes as an introduction to the application before the application gets on executing. During the application loads up into memory there are lot of things happen in background. The process is created in memory, memory blocks are allocated, Virtualized File System gets initialized etc. During these phase of loading the application, the application hung up and the user sees the black screen. If this wait becomes too long, the user gets frustrated and might stop using the application as well. The Mobile Marketplace also puts a threshold of 10 seconds in which your application must load, otherwise your application will be rejected from App Store. During this phase, if you show some nice little splash screen to the user without hampering the normal loading of the application, the user will feel much more comfortable with your application.

In this post I will demonstrate how you can create / use splash screen for your windows Phone 7 application and the different approaches available to you for this.

Basically there are two options available before you which will allow you to show your customized splash screen :

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

How to Customize On-Screen Keyboard Layout in Windows Phone 7 application ?

While you want to enter some text in your Windows Phone 7 application, the first thing that you will notice is your very own on – screen keyboard. As Windows Phone 7 mobile have a very large screen area, most of the phones does not have an analog keyboard associated with it. Hence your application should provide provision to handle keyboard events directly using on-screen keyboards. There are few flexibilities available to you while you define your input scope, in this post I will demonstrate them with an example.

What is InputScope?

InputScope is a special functionality to the developers to customize how the layout of the keyboard appear to the user while entering data into that particular textbox. Hence you can easily customize the On-Screen Keyboard for your input so that one can easily feed in data fast and easy. For instance, say if you want to take phone number as input,you need only digits and some special characters to be available, on the other hand, email needed alphanumeric characters with @ as symbol. Silverlight introduces the new option to let you specify the InputScope for a particular input. Lets look into the code below :

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

Async support for Silverlight and WP7

Async support in C# language brings the new life to the modern application development to bring forth the same technique of writing your code and bring asynchrony easily. The main focus of async ctp is to ornament the language in such a way so that the developer could seamlessly create applications that brings asynchrony yet not dealing with its complexity. Hence using the new technique, asynchrony could easily achieved in a program without refactoring the whole program with lots of callbacks and method calls. I have already talked about it in a separate article. If you don’t know, please visit “Async CTP 5.0”.

Async CTP is released again recently and announced in MIX 11. Just after it is released, the first thing that everyone looks for is what is new in the release. As a matter of fact, I did jumped back to see them but eventually found out that there is nothing new in this build in terms of new features is concerned but the release focuses on fixes of performance adding debugging capabilities etc. I will definitely look back to them later in another post, but in this post I am going to talk about another important thing that featured with this release. As opposed to the previous release, the current release now supports Silverlight and Windows Phone 7 environments. This seems to be interesting.

What is Asynchrony?

The word asynchrony means something that is running without blocking other operations running in parallel. If you have created a background Thread to process some data, you are actually doing asynchronous job in background as your foreground operation does not get hampered. In vNext C# introduces Asynchrony using TPL. The two new keywords “async” and “await” could be used to make one sequential method asynchronous. Hence the new way of developing asynchronous program replaces the traditional approach where we needed to refactor the code totally to gain asynchrony in our application. Basically, this is done using the StateMachine to store the entire method into a form of states, and each states are delegated into batch of statements. The Task.ContinueWith is used in the system to ensure that the method body gets executed sequentially. Yes, it’s a compiler trick. If you want to know more about it, please read through my entire article on “Async CTP”.

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

Application Bar for your Windows Phone 7

If you are working with Windows Phone 7, the first thing that you should have noticed is the very own Application bar. Application Bar is present in most of the applications that you use in your Windows Phone 7. This is basically a standard Toolbar with a menu associated with it which allows you to enumerate the commonly used commands in a standard location. While creating your application, Microsoft strongly recommends you to add an application bar, to ensure the user have common behaviour for every application. You can think Application bar similar to TaskBar of windows.

Components of Application Bar

An application Bar is made up with two components:

1. ApplicationBar Buttons
2. ApplicationBar Menu

The applicationbar buttons are always visible for an application which is used to list only the items that needed to be frequently used while dealing with the application. Lets say you create a Text processing application, you can list the File->Open and File-Save commands as ApplicationBarButtons.

ApplicationBarMenu pops up when the user clicks on either the blank space of the application bar or the special button with 3 dots. The Application Menu is used to list the items that are not used often but needed sometimes in the context.

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

Working with Isolated Storage for Windows Phone 7

During the last few days, Microsoft is getting more and more inclined towards improving the user experience in more than  a number of technologies. Silverlight being one of the major forerunner on this moving good in Web by providing Rich Internet Applications for end users. But not only for Web, Silverlight is a language being used for Windows Phone 7 as well, which gives the silverlight developers a chance to move over to Windows Phone easily. Being a WPF developer, I am totally freaked out on watching stuffs related to Windows Phone as richness in UI always attracts me. I have learned a few about Windows Phone 7 as well, but never got a chance to speak about it. Lets speak a little about the use of Isolated Storage (if you have already read my article here),  in Windows Phone 7 in this article.

Isolated Storage

We say Files and Folders are the building blocks for any application. We need to store data in our Phones to persist data when the application is not running. In case of Windows Phone 7 microsoft provides a secure way to store data into Isolated Store. Isolated Storage, as the name suggests is a special virtualized file system that every application can access for standard IO operations yet the file is unavailable to any other application. Hence the files stored by one application is isolated from another.

Each application has a root of the store of this Virtualized File system. You can use the store to create folders and files. The main advantage of the Isolated store is independence between the actual file system and the application. Hence it gives a strong decoupling between the actual physical architecture of the system and the application. To understand, lets see the image below  :

Here we have three applications running on Windows Phone, and each accesses its own root in the Virtualized file system for data storage. The application API cannot access the physical file system, but interacts with the Virtualized File system for its I/O operations. Thus if our physical file system changes, our stores will still be available and our application will run independently.

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

Closures in CSharp

Closures are an interesting feature for a language. I have heard a lot of questions around how we can declare closures in C# and hence I thought to start a blog on it. Over the internet, there are lots of examples on closures available which are taking help of functional languages like F#, yes it is very important in perspective of these languages as those are easy to declare and also inherently supported yet other languages like C# or VB.NET can also take help of these feature. Lets take a look how C# can take help of closures in this post.

What is a Closure? 

Closures may be defined as a set of behaviour or instructions that are encapsulated as an object such that it could be sent to other object yet can hold the context of the caller.  In other words, a closures are special object that are encapsulated into an object but can hold the context of the caller.

In C# we define closures using delegates. In C# 3.0 we have language support to easily declare a delegate in a program. This widely increases the use of delegates in the program using lamda expressions. Lets put the closures in terms of some examples.

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

Silverlight 5 Beta - Lets deal with its features

In MIX 2011, we can see our very own silverlight new version called Silverlight 5 beta is released. Yes, if you are looking for it, its time to download the beta and try them out. The major goal of Silverlight 5 is to move the silverlight development more towards the WPF and hence releasing some of the benefits that you already enjoy being a WPF developer is now available to silverlight. In this post lets talk about the features that were introduced with Silverlight one by one.

To install Silverlight 5

To try the features, you first need to download the Beta. Lets follow the steps to install silverlight in your machine.

  1. You first need to download Visual Studio 2010 (SP 1) if you didn't have done that already. 
  2. After you install Visual studio update you need Silverlight tools for Visual Studio
  3. Optionally you can also try Silverlight help tools to get started.
Now after you are done with this, lets talk about few basic features introduced in Silverlight 5.

Silverlight 5 Features 

You should notice that there are few major benefits that are not present yet with Silverlight 5 beta, to name a few :
  • Our old requirement to support 64 Bit is not present
  • You still cannot launch external applications (using PInvoke) with elevated trust level
  • DataContextChanged is still not present.
  • Vector Printing

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