Monthly Archives: August 2012

ASP.Net life cycle in plain English

ASP.NET Page Lifecycle is very important piece of knowledge every ASP.NET developer must know, and unfortunately some of ASP.NET developer out there don’t know and they think it’s not important to know.

Let’s dig in and let’s examine ASP.NET Lifecycle but in short list and description:

  1. PreInit():
    • In this event all Controls created and Initialized with their default values. You can create dynamic Controls here. You can set theme programmatically here
  2. OnInit():
    • In this event you can read the Controls properties the were set in Design Mode and can not read values changed by user.
  3. LoadViewState():
    • This event fires only if the page is posted back “IsPostback == true;” and here View State data where are stored in hidden form fields get de-serialized and loads all controls View State data.
  4. LoadPostBackData():
    • This event only fires when Page is posted back and Controls which implement IPostBackDataHandler interface get loaded with values from HTTP POST data.
  5. Page_Load():
    • This event is well known among ASP.NET developers and here Page gets loaded and after it all Load() events of Page Controls fired.
  6. Control Event Handlers:
    • These are basically event handlers like Button click event handler “Button1_Click()” which fires after Page_Load() event.
  7. PreRender():
    • This event is fired for each page child controls and her you can change controls values.
  8. SaveViewState():
    • In this event Controls View State saved in Page hidden fields.
  9. Render():
    • Here all Controls get rendered or every Page Controls Render method is called.
  10. Unload():
    • Here we can have Page and Controls clean up operations. This event the Page and its Controls are rendered.

Notes:

  1. ASP.NET Lifecycle will be called ever time there a request for the page.
  2. HTTP POST data has only one value per control, that’s why Control like Textbox can gets value from HTTP Post but Control like DropDownList can not gets data from HTTP Post it can gets data from View State.
  3. Init() and Unload() events are fired from outside to inside controls, fro example: user control Init() event will be fired beforePage_Init() event
Advertisements

1 Comment

Filed under ASP.Net

WCF Concurrency and Throttling

WCF concurrency tells how it can serve multiple requests at same time.

WCF instance dictates how objects are created.

WCF concurrency dictates how many requests can be handled by WCF objects.

The reasons why we need concurrency are Increase throughput and Integration with a legacy system.

There are three types of WCF Concurrency:

  • Single

Only one request will be processed at any given moment of time. The other request have to wait until the request processed by WCF service is completed.

  • Multiple

Multiple requests can be handled by WCF service object. Requests are handled at the same time by multiple threads on WCF service object but we need to take care of concurrency issues.

  • Reentrant

A single request thread has access to the WCF service object, 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.

Below is the example:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

References:

http://www.codeproject.com/Articles/89858/WCF-Concurrency-Single-Multiple-and-Reentrant-and

Leave a comment

Filed under WCF

WCF Instance Management

WCF can control how WCF service objects are created on WCF server using Wcf Instance. There are three ways of WCF instance creation InstanceContextMode.

  • PerCall (default)
  • PerSession
  • Single


PerCall

Create a new WCF instance on every WCF client call

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
public class MyService : IMyService

PerSession
Ony one WCF instance is created for all the call from a WCF client session.

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class MyService : IMyService
{

NOTE:- If you doesn’t create Sessionful binding then PerSession will act as PerCall. As a result every request to the service creates a new instance of the service class. http://forums.silverlight.net/t/118971.aspx/1

Single

Only one global WCF intance should be created for all WCF clients.

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class MyService : IMyService

Leave a comment

Filed under WCF