Labels

Monday, June 21, 2010

Silverlight - Startup Sequence

Application Events

 

1.    The user requests the HTML entry page in the browser.

2.    The browser loads the silverlight plug-in. It then downloads the XAP file that contains your application.

3.    The Silverlight plug-in reads the AppManifest.xml file from the XAP to find out what assemblies your application uses. It creates the Silverlight runtime environment  and then loads your application assembly (along with any dependent assemblies).

4.    The Silverlight plug-in creates an instance of your custom application class (which is defined in the App.xaml and App.xaml.cs files).

5.    The default constructor of the application class raises the Startup event.

6.    Your application handles the Startup event and creates the root visual object for your application.

 

From this point on, your page code takes over, until it encounters an unhandled error (UnhandledException) or finally ends (Exit).

 

These events– are the core events that the Application class provides

 

·         Startup,  

·         UnhandledException, and

·         Exit

 

Along with these standards, the Application class includes two events– that are designed for use with the out-of-browser applications

 

·         InstallStateChanged and

·         CheckAndDownloadUpdateCompleted

 

Regards,

Arun Manglick

Tuesday, June 8, 2010

C# 4.0 - Optional Parameters and Named Arguments

This post covers two new language feature being added to C# 4.0 – Optional Parameters & Named Arguments.

 

Optional Parameters

 

·         C# 4.0 now supports using optional parameters with methods, constructors, and indexers (note: VB has supported optional parameters for awhile).

·         Parameters Are Optional When A Default Value Is Specified as part of a declaration. E.g.

 

 

public void SendMail(string toAddress, string bodyText, bool ccAdministrator = true, bool isBodyHtml = false)

{

    // Full implementation here

}

 

Now the call could be made as:

 

email.SendMail("bob@foo.com", "Hello World");

email.SendMail("bob@foo.com", "Hello World", true, false);

 

 

 

 

Note: But this approach will not let you pass the value for 4th parameter - isBodyHtml and utilize optional feature for the 3rd one. Here comes the usage of Named arguments.

 

Named Arguments:

 

·         C# 4.0 also now supports the concept of “named arguments”. 

·         This allows you to explicitly name an argument you are passing to a method – instead of just identifying it by argument position.

 

·         This enables us to call the above method as: Let you pass the value for 4th parameter - isBodyHtml and utilize optional feature for the 3rd one

 

 

email.SendMail("bob@foo.com", "Hello World", isBodyHtml: true);

 

 

 

Overall, it’s by no means an earth shattering feature that is being added to the language in stand-alone scenarios

 

Reference : Link

 

Hope this helps.

Arun Manglick