Wednesday, June 25, 2008

WinForms : DesignMode

Back to WinForms...It was a user control which calls a service, I knew that if I wrap the service call inside a ComponentModel.DesignMode, I could get away with the service call being called at design time and the designer throwing me exceptions...Now this is not an issue at all when your are designing the control, cos' Visual Studio does not create an instance of the user control that is being designed, instead it creates a base class, UserControl, this is also true when you designing a form, a Form instance is created. Therefore .ctor of the control being designed is never called, so doesn't the service call.Now if I drag an drop this control (ctrl1) into another a control(ctrl2), the control's DesignMode property is true, but if I now drag the ctrl1 into a form, the DesignMode of ctrl1 is false.This basically means that ctrl2 is sited in the form and not ctrl1, makes sense right?.There are two work around that you can use to avoide this...1) See if the current process that is hosting the form is devenv, This is not a flexible solution, as this will not work if you open your view in a different environment.2) Use the LicenceManager class to see if we are in DesingMode or runtime.

Friday, June 13, 2008

Going Parallel With Parallel Extension For .Net 3.5

Now a days, almost all computers being used have multiple cores, for an example technologies like dual core.But, although you have dual core, generally you write programs that run on a single core, this does not utilize the total power of the multiple CPU or core that you have.
This is exactly the power what Microsoft Parallel Extensions for .NET Framework 3.5 (a.k.a PFX).gives you.
With PFX, you can write flexible programs that would take advantage of utilizing multiple cores in the environment it is deployed in, giving you high performance and scalabilty.
PFX comes in 2 "Flavours", Task Parallel Library (TPL) and PLINQ.
TPL gives you general APIs that can be used to make your program run in parallel, for an example , take the for loop below
for(int i = 0; i < 1000000; i++ )
{ //Do something that is not dependent on other iterations }

the for loop does 1000000 iterations, and does something that is not dependent on other iterations. Running this program in a mulit core machine , will only utilize one CPU and not at it's best and eventually the response time is also high.
This for loop can be easily made to run in parallel, as the iterations are not dependent on each other.
With PFX, you can re-write your program like this

Parallel.For(0, 1000000, i => (/*Do somthing */));

This program would run faster as PFX assigns chunks of iterations to the mulitple CPUs. You would also see that the almost 100% of CPUs power is used if you are on a dual core.
Parallel is a class in the PFX that gives you high level static APIs for looping and invoking in parallel, you can have a look at the docs if you want more... :)
PLINQ on the other hand, is a way to make your queries run in parallel, this applies to in-memory objects and xml. Queries that hit databases is not a candidate for parallisam and hench cannot be used with PLINQ.You can find some introductory samples and videos at the MSDN Parallel Computing section.

Wednesday, June 11, 2008

Weekend at Namunukala.

Last weekend we took some time off, at Bandarawela. Climbing the Namunkala mountain and visiting some natural pools. It was a fun guranteed trip after all. This is our team.



Monday, June 9, 2008

Velocity : Distributed Caching

Caching is one way you could increase your applications response time. For an example, take
a hotel reservation system, where you might need to show a list of hotels for a particular
country in your reservation page.

For each and every reservation made by users, a service call or a direct database call is onvloved to fetch the list of hotels for the country the user has selected, and when the number of concurrent users to your system increases, the performance of your system decreases too.
To avoid these hits, caching of your hotel objects or a hotel dataset can be used, so you application can use these to respond to a request without calling the service or making a call to the database, further more the cache is updated at periodic intervals to accomadate changes to the underlying data.
Velocity is an in-memory distibuted caching solution from Microsoft, still in it's CTP,
addresses application scalabilty.

In typical applications you would cache your data in the host your application is running
in, but using Velocity, you can configure muiltple hosts (nodes) to act as your application's in-memory cache, in other words, your application cache is distributed.
This adds on the capabilty to scale you application, for an example, if a need arises, you
can easily add a another host to your existing distributed cache so increasing the
performance and through put of your application.

Although your cached objects are distributed, Velocity gives you an interface to retrive your
cached objects in a unfied way, that is in your code you would access your cached
objects as if they reside in your local machine without the need to identify in which host
the actual cached object resides.

Velocity also gives you the capabilty to duplicate your cached object in terms of a primary and secondry "caches", so that you can stil use your secondary cache if your primary cache fails, making availabilty first class.You can read more about velocity here

Thursday, June 5, 2008

Better Late Then Never

It's been a few weeks since I have blogged, was a bit hooked up on catching on with some of the MS technologies.I started learning the ADO.Net entity Framework, downloaded some videos, samples and ye, did some pretty intresting stuffs with it.Then there was last week, when one of my friends asked me a question on web services, got a bit confused and I had to dig into some of the ws-* standards and WCF Security, and finally thought of going through the specificaions at w3c, and I ended up reading the ws-security and ws-addressing spec.Then there was this week, started looking at some presentations on the ADO.Net data services on MIX 08, still doing this !!!. and another thing about all these is that I am getting not much of time to do all these readings, cos' I have hooked up into some of the old cartoons that I always wanted to watch, like the X-Men, King Artuher, The Mask etc...Well for all, I guess its better late then never !!!