Monday, September 6, 2010

Windows Phone 7 and Development Tools



In previous blog we talked about all Windows Phone 7 and new features. Today’s topic is more developers oriented and we will talk about what are basic development tools we will need to start with windows phone 7 development.

Microsoft provides two different frameworks for developing Windows Phone 7 Application.

XNA Framework: To develop Windows based games.
Silverlight Framework: To develop event based and XAML based Windows Phone 7 Applications.
So first let’s see what development system requirements are:

•Windows Vista (x86 and x64) ENU with Service Pack 2 – all editions except Starter Edition
•Windows 7 (x86 and x64) ENU – all editions except Starter Edition
•Installation requires 3 GB of free disk space on the system drive.
•2 GB RAM
•XNA Game Studio deployment to Windows Phone Emulator requires a DirectX 10 or later graphics card with WDDM 1.1 driver.
•DirectX 10 capable card with a WDDM 1.1 driver is needed to take advantage of GPU acceleration on the Windows Phone Emulator for a Silverlight application. The DX10 card is optional for Silverlight applications.
•Windows Phone Developer Tools BETA - compatible with the English version of Visual Studio 2010 RTM and Visual Studio 2010 Express.

And here are the steps to setting up Development Environment:

Download Microsoft Windows Phone 7 Developer Tools Beta from the link below and follow the steps.

http://www.silverlight.net/getstarted/devices/windows-phone/



Assume that machine is ready with development system requirement (i.e. OS, HD, RAM).

Step1: Install the required version of Visual Studio 2010 (Skip this step if already installed)

Microsoft provides two different frameworks for developing Windows Phone 7 Application.

•XNA Framework: To develop Windows based games.
•Silverlight Framework: To develop event based and XAML based Windows Phone 7 Applications.
So first let’s see what development system requirements are:

•Windows Vista (x86 and x64) ENU with Service Pack 2 – all editions except Starter Edition
•Windows 7 (x86 and x64) ENU – all editions except Starter Edition
•Installation requires 3 GB of free disk space on the system drive.
•2 GB RAM
•XNA Game Studio deployment to Windows Phone Emulator requires a DirectX 10 or later graphics card with WDDM 1.1 driver.
•DirectX 10 capable card with a WDDM 1.1 driver is needed to take advantage of GPU acceleration on the Windows Phone Emulator for a Silverlight application. The DX10 card is optional for Silverlight applications.
•Windows Phone Developer Tools BETA - compatible with the English version of Visual Studio 2010 RTM and Visual Studio 2010 Express.
And here are the steps to setting up Development Environment:

Download Microsoft Windows Phone 7 Developer Tools Beta from the link below and follow the steps.

http://www.silverlight.net/getstarted/devices/windows-phone/



Assume that machine is ready with development system requirement (i.e. OS, HD, RAM).

Step1: Install the required version of Visual Studio 2010 (Skip this step if already installed)

Step2:
Start Windows Phone 7 Tools Beta installation by double clicking on vm_web.exe which is
downloaded from the link above. The vm_web.exe is online installer and will download and install
following tools:



•Microsoft Silverlight for Windows Phone 7 Beta
•Microsoft Expression Blend for Windows Phone 7 Beta
•Microsoft XNA Game Studio for Windows Phone 7 Beta
After following these steps your development environment is ready for developing Windows Phone 7 Applications.
Note: During installation, an active internet connection is required.

While doing development for Windows phone please note following important points:

•While you develop Silverlight UI [using xaml] you need to understand and follow certain guidelines. Microsoft has provided Control Templates specific to Silverlight application for Windows Phone to match evolutions in the overall OS. Start Windows Phone 7 Tools Beta installation by double clicking on vm_web.exe which is
downloaded from the link above. The vm_web.exe is online installer and will download and install
following tools:



•Microsoft Silverlight for Windows Phone 7 Beta
•Microsoft Expression Blend for Windows Phone 7 Beta
•Microsoft XNA Game Studio for Windows Phone 7 Beta
After following these steps your development environment is ready for developing Windows Phone 7 Applications.
Note: During installation, an active internet connection is required.

While doing development for Windows phone please note following important points:

•While you develop Silverlight UI [using xaml] you need to understand and follow certain guidelines. Microsoft has provided Control Templates specific to Silverlight application for Windows Phone to match evolutions in the overall OS.

•To make it easy to create XAML UI for Silverlight application Microsoft has made available Expression Blend for Windows Phone, Blend is now integrated completely into the Windows Phone Developer Tools Beta.
•Using Developer Registration Utility you can unlock you Windows Phone 7 device for development purposes.
•If you want to deploy XAP files directly to an unlocked device, you can use XAP Deployment Tool.
•If you planning to create virtual development environment then wait at present following Scenarios Not Supported For Development Environment:
◦Windows XP and Windows Server are not supported.
◦Virtual PC and Hyper-V are not supported.
•Windows Phone Developer Tools Beta includes database components. These components are not supported for application development.
•When using Visual Studio 2010 Ultimate for Silverlight application development for Windows Phone , the following features are not supported:
◦Profiler
◦IntelliTrace
◦Lab Management
◦Testing
◦Data
◦Show Data Source
◦Add New Date Source
◦Schema Compare
•If you are using Visual Studio 2010 Ultimate or Professional for Silverlight application development for Windows Phone, Add Service Reference features not supported. To Add WCF Service Reference in your application in VS2010 Professional or Ultimate, you have to run
slsvcutil.exe from visual studio command prompt in order to generate Service Reference and Client Configuration file. Click here to see How to use slsvcutil.exe.

Windows Phone 7 Project Templates for Silverlight:

Once your development environment setup done, open visual studio and try to create new project of type “Silverlight for Windows Phone”.
There are three types of template to start development of Windows phone 7 for Silverlight.



1.Windows Phone Application: A project for creating windows phone application.
2.Windows Phone List Application: A project for creating windows phone application using List and Navigation Controls.

3.Windows Phone Class Library: Windows Phone Class Library Project.
That’s it your development environment is ready to go for developing app for windows phone. Microsoft's Windows Phone Developer blog is claiming that over 300,000 people have downloaded the Windows Phone Developer Tools so far and this number is increasing rapidly.


In next post I will talk more on specific to silverlight application development for Windows phone 7 .

Windows Phone 7 and new features


In previous blog we talked about all 7 hubs those coming with Windows Phone 7. Today I will tell about new features or you can you software and hardware coming with this version.

Actually Windows Phone 7 is based on Windows CE 6 Kernel and is a touch-operated OS and it is news that initial launch it will be available with resolution WVGA (480 x 800) and sooner it will support HVGA (320 x 480). And to run consistently it will need device equipped with
• 1 GHZ CPU
• Min 256 MB RAM
• Finger based Device content Navigation
• WI-FI, GPS, FM-Tuner and High Resolution Camera
Additional to all common feature of today’s phone device, windows phone gives following featured Software’s:
User Interface: in this version UI is drastically changed and developed based on interfaces of the ZUNE and Windows Media Center. The home screen viewed as of "tiles", which by default are links to important features such as phone, music and videos, email, office, and contacts.
Silverlight Support: for Silverlight developers its good new that after long waiting Microsoft introduce Silverlight support in Windows phone series. So developers need to start exploring what and how to do silverlight development for windows phone and there will be defiantly huge requirements for developing silverlight application for Windows phone.
Browser: Yes you all right it will be Internet Explorer only. Browser will be a modified version of Internet Explorer 7, which will not support Flash, Silverlight and HTML5 at launch. The specialty of this browser will be to automatically update itself and the layout engine.
Xbox LIVE: Xbox LIVE experience on a phone, including Xbox LIVE games, Spotlight feed and the ability to see a gamers’ avatar, Achievements and gamer profile




Search: Yes Microsoft Bing will be the only default search engine on Windows Phone 7 devices.




Email and Calendar: As it will be integrated with light version of office outlook it will supports outlook POP mail and calendar with some fancy UI.




Me: this hub will be center to aggregates all social media and XBOX live content – to update Social Networks.
• Software Updates: According to news channel, this phone software updates will be delivered to Windows Phone users via Microsoft Update, as they are for desktop Windows users.
Zune: Integrated media player is basically the Zune- its look and feel, functionality and the Zune Pass subscription support which allows unlimited music streaming.
Marketplace: This hub will make you easy to access center for find and download suitable certified software and games for your device. Click here to see more about Marketplace.




It looks Windows Phone 7 devices will work 100% consistently across hardware coming from HTC, Samsung, LG and Dell.

In next post I will talk more on Windows phone 7 application development.

Exploring Windows Phone 7 Series 7 Hubs



Windows Phone 7 is emerging Microsoft’s operating system for windows phone devices. This new Operating system is going to drastically changed supported device skin with amazing User interface and lots many more features.

Basically Windows Phone 7 Series includes six hubs built on special themes those are mostly liked by end user and used in their daily activities:

1. People. This hub specific for an engaging you with your social networks and make you connected with live feeds from social networks and media.
2. Office. This is best hub I liked most because it connects me with my daily work as it has provided with access to Office, OneNote and SharePoint Workspace all in one place.
3. Browse and Bing Search: This is going to appreciates by the people who love to travel and explore new places, this hub will fully equipped with Bing maps to help you to see maps and directions. And also Quick Search like a pro when surfing by highlighting the word and hitting “search”.
4. Marketplace. This hub will make you easy to access center for find and download suitable certified software and games for your device. Click here to see more about Marketplace.
5. Pictures. This hub makes it easy to share pictures and video to a social network in one step. Windows Phone 7 Series also brings together a user’s photos by integrating with the Web and PC, making the phone the ideal place to view a person’s entire picture and video collection.
6. Games. This hub will be for those game lovers who already playing Xbox LIVE games, as this hub will include Xbox LIVE experience on a phone, including Xbox LIVE games, Spotlight feed and the ability to see a gamer’s avatar, Achievements and gamer profile.
7. Music and Video. This hub will bring incredible media experience to those music lovers as it will provide you best of Zune, and will allow you to include media content from a your PC, online music sites and built-in FM radio.



Microsoft Windows phone development team is planning to release Windows Phone 7 by October 2010, so keep you updated with Windows phone 7 news.
In next post I will talk more on Windows phone 7 features.

Sunday, July 25, 2010

Silverlight application and Performance nuggets

Silverlight application and Performance nuggets

So far I worked with Silverlight different versions to develop many RIA applications, World is moving toward Rich interactive application, customer wants to have their web application more interactive and end user centric. And customers are now realizing importance of migrating their simple html web app to RIA; because of Rich user experience they found benefits in end user stickiness to their app and ultimately growth in their business.

I started working on Silverlight 1.0 application those codes in JavaScript, and now Silverlight 4 is emerged where we develop code behind in C#, Vb.net and other supported manage codes. After working with different Silverlight application I realized that while matching customer and design expectation it’s very important to keep eye on application performance. And so I came up with certain important check point to validate that we are not compromising on application performance.

Performance checks for Silverlight app:

Avoid using .findName to access control from XAML:

function onLoginButton_Click(sender, args)

{

var txtLogin = sender.findName('txtLogin');

string strloginName = txtLogin.Text;

}

FindName has to walk through the tree of XAML objects to find out expected match which is very performance perspective. Either you can try following options:

  1. Naming the target element and use it directly where it required [using x:Name in xaml]
  2. Using findName initialize object in application loaded event, and use stored global reference where it required.

Avoid naming elements if it really not needed:

Many times we do not concern while naming xaml element. Designers give naming to make it easy for them to navigate through templates/ object trees in Blend they creating. We developers does not care while naming controls like border, stackpanel etc. but let me tell fact that for every naming XAML markup creates a variable. Obviously each of those variables eats precious byte space in the InitializeComponent call. I will suggest:

  1. Use naming only for controls those referred in code behind like Button, TextBox, ListBox, etc
  2. Avoid naming controls like TextBlock,Border, borders, lines, rectangles and similar.
  3. Use data binding where there is need to refer controls

Don’t ignore importance of settings while integrating Silverlight applications in web pages

When we create Silverlight application in visual studio it creates test web pages .aspx/.html. And we developers go live with same test pages; there some small setting can help us to improve good performance.

  1. 1. Avoid Using Windowless Mode

Set the Windowless property to true only when necessary. The default is false. Windowless mode is highly expensive. More..

  1. Reduce MaxFrameRate

You can see the MaxFrameRate value by enabling a performance-tuning option that displays frames per second for Silverlight rendering. This maximum number of frames that Silverlight can render per second. The default value is 60 second. You can reduce this to desired number.

To set parameter of object on HTML page:

param name="framerate" value="24"

To set it in Silverlight code:
App.Current.Host.Settings.MaxFrameRate=24;

Set the frame rate of your application to only be what is needed. For video, you will want around 60. For animation, around 20-30.
More..

  1. Use EnableGPUAcceleration

Basically GPU is a processor attached to your graphics card that is generally used for calculating floating point operations. In addition, it is very useful to save you a lot of CPU time.

To enable EnableGPUAcceleration on your Silverlight control For HTML modify the Silverlight control to include the following param:

param name="EnableGPUAcceleration" value="true"

For ASPX add the following attribute:

asp:Silverlight ID="SilverlightControl" EnableGPUAcceleration="true" runat="server" Source="~ /SL.xap" MinimumVersion="3.0.40307.0"

For silverlight controls set CacheMode in code behind like:
ControlGrid.CacheMode = new BitmapCache();

else in XAML:

Grid x:Name="ControlGrid" CacheMode="BitmapCache"

  • To use it you must enable it both on your Silverlight control/plug-in as well as any of the controls you want to leverage it.
  • By default this option is disabled.

And it enables visual controls to be cached as bitmaps and whenever re-rendering required we can bypass the expensive rendering phase for the cached visuals and just display them.

More..

Replace Opacity by setting Visibility

Always use setting Visibility to Collapsed or Visible instead of fading or change elements opacity. Because Opacity is associated with higher costs because the object is still hit tested and technically rendered.

Animations

  • Many and big size controls animations are highly CPU costly as there is redrawn regions and multiple frame calls. So avoid such heavy use of animations or try to minimize their frequency.
  • There is additional cost to animate properties like height, width, visibility, alignments and margin as that call to layout relevant changes.
  • Avoid Text resizing animations, as there is extra cost to optimize text for readability.
  • We can always use images replace to static text.

Tools to profile Silverlight applications

There are many tools out for profiling your Silverlight applications, select one of them as per your application and need. Here are some samples:

1. Visual studio profiler

2. Xte profiler

Threading

Threading is basically used to multiple concurrent jobs in same application. Using threads in your Silverlight application can improve performance by increasing the responsiveness of your application. There are multiple ways you can try in Silverlight.

- Using Threadpool

  • allows you to spawn multiple background threads.

- Using Dispatcher class

  • The Dispatcher class greatly simplifies calling the UI thread with a static method BeginInvoke.

- Using DispatcherTimer

  • The DispatcherTimer is a special timer integrated into the Dispatcher queue that is reevaluated on every Dispatcher loop

- Using BackgroundWorker class.

  • provides an easy way to run time-consuming operations on a background thread. The BackgroundWorker class enables you to check the state of the operation and it lets you cancel the operation

Other important points to be noted

  • Do not create only 1 single xaml for all UI. Cut it in separate controls and use them whenever required.
  • Do best utilization of UI thread, as Silverlight has full control of the UI thread.
  • Handle memory leakage, and do not forget to stop threads, background calculation, if not needed.
  • Do not create redundant styles create a separate resource files for styles and use them as required.
  • Try to do best utilization of storyboards because Silverlight performs animation it only redraws the dirty rectangles.
  • Always use Image.Stretch = “Fill” to load large images to prevent any layout updates due to stretching. So if you use Stretch = “Fill” there is no potential clipping happening which adds extra edges.
  • Do not specify Width and Height for following controls, Let plug-in render it at its natural size.
  1. MediaElement - let the media element display at its natural size. If you need to change the display size of the element, it is best to re-encode the media to the desired size by using a media encoding tool
  2. Path - Setting explicit Height & width calls additional stretching, which affects performance. better rely on the explicitly set coordinates of the Path object to control its shape and position.[basically avoid using Path controls as they very heavy to use]
  • If application is very large, consider loading pieces of it "on demand".
    1. Break up large application in controls and modules
    2. We can do on demand .xap ,assembly, resource files download
  • Avoid setting Transparent Background for Silverlight controls.
  • SL app Loading time increase because of your XAP file. if you use more image, video in sliverlight project XAP file size will be increasing.
  • Avoid large use of event handlers. When you attach normal events, registering an event handler creates a strong reference from the event source to the listening object, And this reference persist still the lifetime of event source.

Reference:

http://msdn.microsoft.com/hi-in/bb693295(en-us).aspx

http://www.microsoftpdc.com/2009/P09-10

http://silverlight.newagesolution.net/SilverlightTutorials/UsingThreadpoolInSilverlight.aspx