Wednesday 22 August 2012

Dispose method


Calling Dispose will not clean up the memory used by an object. Dispose is meant to be used to run user defined code that releases resources that are not automatically released - like file handles, network handles, database connections etc.
The likely culprit is probably the second form attaching events to objects that are outside it (perhaps the first form?) and never unattaching them.
If you have any events in the second form, unattach them in your OnClose override - that will make the second form eligible for garbage collection.
Note, .NET garbage collector is quite unpredictable and it might create a few instances of an object before cleaning up all the older instances that were eligible for collection. A way to know for sure (without resorting to memory profilers) is to put a breakpoint in the finalizer:
public class MyForm : Form {
 
~MyForm() {
   
//breakpoint here
 
}
}
If the finalizer gets called then this class is OK, if not, you still have a leak. You can also give GC a "kick" - but only for troubleshooting purposes - do not leave this code in production - by initiating GC:
GC.Collect();
GC
.WaitForPendingFinalizers();
GC
.Collect();
Put the above code somewhere that runs after you close and dispose the second form. You should hit the breakpoint in MyForm finalizer.

Friday 3 August 2012

Silver Light Introduction


Silver light is a new cross-browser, cross-platform implementation of the .NET Framework for building and delivering the next generation of media experiences and Rich Interactive Applications (RIA) for the web. It runs in all popular browsers, including Microsoft Internet Explorer, Mozilla Firefox, Apple Safari, and Opera. The plug-in required to run Silver light is very small in size hence gets installed very quickly.
It is combination of different technologies into a single development platform that allows you to select tools and the programming language you want to use. Silver light integrates seamlessly with your existing JavaScript and ASP.NET AJAX code to complement functionality which you have already created.
Silver light aims to compete with Adobe Flash and the presentation components of Ajax. It also competes with Sun Microsystems' JavaFX, which was launched a few days after Silver light.


Silverlight provides a Rich Internet Application (RIA) framework that can be used to build applications that can be deployed through the Web while preserving the rich client-side functionality found in traditional desktop applications. This lab is designed to guide ASP.NET and jQuery developers through the process of migrating applications to Silverlight.
In the lab you'll convert an existing ASP.NET/jQuery application that consumes data from a Windows Communication Foundation (WCF) service to Silverlight and ensure that existing functionality is preserved. Along the way you'll learn how to create a Silverlight user interface, handle events, make asynchronous calls to services, bind data to controls, plus more.
You'll start by researching existing data access and WCF service projects used by an ASP.NET application. Next, you'll run the ASP.NET application to see the feature set that will be migrated to Silverlight. To accomplish the migration you'll create a new Silverlight project in Visual Studio 2010 and use eXtensible Application Markup Language (XAML) along with managed code (both C# and VB are supported in the lab).



Business Requirements for the Silverlight application include:
  • Create a new Silverlight project and associated ASP.NET Web Application project
  • Re-use existing data access and WCF service code
  • Use XAML to define the user interface and emulate the ASP.NET application
  • Handle user interface events
  • Create a WCF service proxy
  • Call the WCF service using the asynchronous programming model
  • Bind data to controls using Silverlight binding syntax
  • Handle update and delete operations and notify the user about the status of the operation
 

It always depends on what the customer wants (Silverlight is a plug-in that needs to be rolled out after all) and how friendly and feature-rich the UI should be. You won't get a flexible, resizable layout or a grid with user-resizable columns in ASP.NET without 3rd party components, external javascript libraries you'd have to integrate or extensive development by yourself. It also depends on if the application should look more web-like or more desktop-like. In my opinion, developing with Silverlight will yield results a lot faster once you've mastered it. Thus I'd recommend Silverlight, and if it is only for prototyping.