Pages

Showing posts with label CLR. Show all posts
Showing posts with label CLR. Show all posts

6 Jun 2012

WCF - Concurrency, Sessions and Throttling

WCF allows different way for Session and Concurrency management.

Session Management: configures how service object life time is managed during client requests.

  • Per Call - a new service instance is made for each method call from client.
  • Per Session - a single instance will cater all calls from a client.
  • Single Instance - all client calls will work under a single instance of service object.


Concurrency Mode: configures how service instances servers multiple client requests at the same time.
  • Single - a single request will be catered by service object, other requests need to wait during this period.
  • Multiple - multiple requests will be processed by service object by spawning threads. This approach is beneficial for good throughput.
  • Re entrant - single requesting client has access to the WCF service object thread, but the thread can exit the WCF service to call another WCF service or can also call a WCF client through callback and reenter without deadlock.



By default WCF services is configured to have Per Call session, Single ConcurrencyMode.

Throttling behavior of WCF helps in putting upper limit for no of sessions, concurrent calls & instances. Following flags are used for this

  • MaxConcurrentCalls
  • MaxConcurrentInstances
  • MaxConcurrentSessions 


12 May 2012

What is vshost.exe ?

Right next to Visual Studio build of a CLR executable, we notice another executable ending with .vshost.exe


vshost.exe is a hosting process introduced by Visual Studio, for following benefits

  • helps in creating App domain and associating debugger to that. Normally this is a slow process, however vshost.exe makes this noticeably fast.
  • initializes the debugger for partial trust debugging
  • supports intermediate window for design time expression evaluation.
Still don't wish to have *.vshost.exe next your binary, then go to project properties -> Debug
And un-check the option.

26 Apr 2012

Using SqlDataReader on multiple results.

Suppose we plan to execute multiple select query and how do we fetch result using SqlDataReader. Well this can be achieved by using SqlDataReader.NextResult

Example

Create test database and sample tables

create table employee (id int identity(1,1), name varchar(256), primary key(id))
create table employeeaddress (id int identity(1,1), empaddress varchar(256), primary key(id))


insert into employee values('Johan')
insert into employee values('Leon')


insert into employeeaddress values('Eindhoven, The Netherlands')

Now lets fetch results using SqlDataReader, C# program as follows

string cmdText = @"select * from employee;select * from employeeaddress";
            using (SqlConnection sqlCon = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=testDB;Integrated Security=SSPI;"))
            {
                using(SqlCommand sqlCmd = new SqlCommand(cmdText,sqlCon))
                {
                    sqlCon.Open();
                    SqlDataReader reader = sqlCmd.ExecuteReader();
                    int ResultIndex =1;
                    do
                    {
                        Console.WriteLine("Results from table - " + ResultIndex);
                        while (reader.Read())
                        {
                            Console.WriteLine(reader[0]);
                        }
                        
                        ++ResultIndex;
                    } while (reader.NextResult());
                    reader.Close();
                }
            }