Showing posts from December, 2012

Lock keyword in C#

As we have written earlier we have now multi-core CPU for our computers and laptops and to utilize that we need to use threading in code. Now if we create thread and access same resource at same time then it will create a problem at that time locking become quite essential in any programming language.

Let’s consider a scenario. We are having a small firm of computers and each computer is shared by two employees and they need to use computer for putting their sales data in excel sheet. So they can not work together at same time and one has to work and other has to wait till first one complete the work. Same situation can be occurred in programming in where we are using same resource for multiple thread.

C# provides locking mechanism via lock keyword. It restricts code from being executed by more then one thread at a time. That is the most reliable way of doing multi threading programming.

Merry Christmas to all my readers

This is not a usual technical post I am writing here. I just wanted to take a moment and wishing you Merry Christmas and happy holidays. All readers are has been great support to this blog and on this occasion I want thank you guys for all the support and love you have shown during this year 2012. I have achieved so much through this blog and its been not possible without your support.

I wish that year 2013 will bring you all joy and happiness you required. May all your wishes fulfil.

Stay tuned for more. I have lots of stuff for you in 2013. Till then happy holidays!! and once Merry Christmas to you and your family.

Where I can find SQL generated by Linq-To-SQL

Yesterday I have written a blog post about Where I can find SQL Generated by Entity Framework? and same day I got request from one of the our reader Ramesh that how I can find SQL generated by Linq-To-SQL?. I thought its a good idea to write a blog post to share amongst all who need this instead of reply in comments.  In this post I am going to explain how we can get SQL generated by Linq-To-SQL.

For this post I am going to use same table like following. A customer table with two columns CustomerId and CustomerName.

Where I can find SQL Generated by Entity framework?

Few days back I was optimizing the performance with Entity framework and Linq queries and I was using LinqPad and looking SQL generated by the Linq or entity framework queries. After some point of time I got the same question in mind that how I can find the SQL Statement generated by Entity framework?

After some struggling I have managed to found the way of finding SQL Statement so I thought it would be a great idea to write a post about  same and share my knowledge about that. So in this post I will explain how to find SQL statements generated Entity framework queries.

To demonstrate the idea Let’s a very simple console application with C# and then  create a table called ‘Customer’ with CustomerId and CustomerName field in sql server.

Caller Info Attributes in C# 5.0

In c# 5.0 Microsoft has introduced a Caller information attribute. It’s a new feature that is introduced in C# 5.0 and very useful if you want to log your code activities. With the help of this you can implement the log functionality very easily. It can help any programmer in tracing, debugging and diagnostic of any application.
With the help of Caller Information we can get following information over there.

CallerFilePathAttribute: With help of  this attribute we can get full path of source file that contains caller. This will be file path from which contains caller at compile time.CallerLineNumberAttribute:  With the help of this attribute we can get line number of source file which the method is called. CallerMemberNameAttribute: With the help of this attribute we can get the method or property name of the caller.Let’s write a simple example for that to see how its works. Following is a code for that.

Parallel task in C# 4.0

In today’s computing world  is all about Parallel processing. You have multicore CPU where you have different core doing different work parallel or its doing same task parallel. For example I am having 4-core CPU as follows. So the code that I write should take care of this. C# does provide that kind of facility to write code for multi core CPU with task parallel library. We will explore that in this post.

Dynamic URL of web service with web reference

It’s been a while I am writing this. But never late.. So I am writing this. Before some time one of friend asked about the URL of web service when we add reference. So I am writing this. Some of you may find this very basic but still many of people does not know this that’s why I am writing this.

In today’s world we have so many servers like development, preproduction and production etc. and for all the server location or URL of web service will be different.But with when you add a web reference to your web application it’s create a web reference settings in web.config where you can change this path. So it’s very easy to just change that path and you don’t have to add web reference again.