InterOp: Using a .NET based component from a non .NET platform by creating Isolated Application

Whenever we try to use a .NET component from VB6 or VC++ applications we tend to expose the .NET classes as COM components and register them and from the VB6 or VC applications so that we can instantiate and use the COM components written in .NET. One downside to doing interOp this way is the use of Registry to store the COM information as COM uses registry to lookup the prog id and clsid. This hassle can be avoided by using xcopy deployment with Registry Free COM.

Isolated Applications and Side by Side Assemblies

.NET is not the sole platform to come up with xcopy deployment and freedom from dll hell. Cpp and Delphie had this for long time. Isolated Applications and Side by side Assemblies  have been invented as a solution to the versioning problem.

According to MSDN, Isolated Applications are self-describing applications installed with manifests. The benefits of Isolated Applications are that these are more stable and reliable since they are not affected by installation or change in other software, they will always run with the component version they were originally intended for, they can take advantage of Side by Side Assemblies feature, can be installed with xcopy deployment without impacting the registry. A side by side assembly can be a dll, windows class, COM server, type library or interface defined by manifests.

Private and Shared Assembly

There are two types of Side By Side Assemblies. Private Assemblies are those which are for consumption of one single application, usually placed in the application folder or sub folder. But a Shared Assembly can be used by multiple applications. A fully Isolated application uses only side by side assemblies. If you want to find the Shared Assemblies installed in your computer look in \Windows\WinSxS folder. The shared assemblies are installed here.

Manifests

Manifests are xml files that accompany assemblies with extra information like dependency, binding, activation. A manifest can be an external file or can be embedded as a resource within the assembly. In older operating systems like Windows XP, manifests need to be embedded inside the side by side (denoted SxS) assemblies to work properly. Assembly Manifests describe side by side assemblies and thus needs to be embedded to work properly in operating systems like Windows XP. Application Manifests describe isolated applications and do not need to be embedded inside the application.

Normal Registry Based COM Component Load Procedure

If we look up a COM self registering dll we will find that it usually* has four stdcall  calling convention functions. Look at the dependency walker image below of a standard self registering COM server dll.

dependency_walker

When we use regsvr32.exe to register a COM dll, the register server application calls the DllRegisterServer function of the dll and that function call inside the dll takes care of putting information in the windows registry so that it can be used by any user application. Now lets have a look at the registry where all these information is recorded. Let us take a standard windows COM component and see its registry structure. The COM component that we will look up today is FileSystemObject from Micorsoft scripting runtime. The progid of the object is Scripting.FileSystemObject. Lets say we are using script code like this

 Set fso = CreateObject( “Scripting.FileSystemObject” )

So lets try to have an understanding how this object is created from the code above. If we go and try looking up the string “Scripting.FileSystemObject” under the HKEY_CLASSES_ROOT key then we would see this.

registry_1

As you can see there is a node called CLSID and it contains the Class ID ( GUID of the class) inside the node. Now lets go and visit that Class ID node under the HKEY_CLASSES_ROOT\CLSID registry node. See below

registry_2

As we can see that this is how the dll containing the class object is found, COM infrastructure then calls the DllGetClassObject function to retrieve a pointer to the object we are looking for. As like all COM interfaces the object implements IUnknown interface and all scriptable COM objects implement IDispatch interface. However how COM identifies and uses the object beyond the scope of this article. The point that I wanted to make is that the windows registry has a very important function here and to have any COM component usable by other applications we had to register it in windows registry. 

Registry Free COM Access in an Isolated Application

In an Isolated Application we can skip entering all the information in the registry and rather enter them in the manifest. We need to create an application manifest which will have the filename in the format of application.exe.manifest. Then we need to create an assembly manifest and embed that assembly manifest inside the dll. Then we would have created an Isolated Application and would not need to register to windows registry to access the functions of the COM dll.

The side by side assemblies are searched in the following order

1. In the executable folder
2. Subfolder of the executable folder, subfolder must have the same name as the assembly. For example see inside your Windows\WinSxS folder
3. In language specific or culture specific subfolder of the executable

For more information on assembly search order look here in MSDN.

Activation Contexts are data structures that allows the OS to redirect loading. For example it can redirect the loader to load a specific version of a dll, or redirect COM object loading process. We will use the COM object loading redirection to avoid using windows registry. For more information on Activation Contexts read this

Doing it by example

I have setup a sample application with source that will show how we can create a registry free COM component. Please note that there is already a practical example in the following article in MSDN, Registration-Free Activation of .NET-Based Components: A Walkthrough by Steve White and Leslie Muller. You might want to read that article if you find my example not clear enough.

Download Sample Code

Here is what we are going to do in the sample application

1. Create C# based class that serves funny quotes and expose that as a COM component and register it.

2. Create a VB6 executable that uses the COM dll to show quotes

3. Unregister the COM dll to show that without COM registration in windows registry the application is no longer working

4. Create an application manifest, then create an assembly manifest and recompile the C# application with the embedded assembly manifest to create our isolated application.

5. Move the isolated application to a different folder and prove that the application is using COM without registry.

1. C# COM Dll

We are going to create a dll called QuoteSource and a class that serves Quotes called QuoteProvider and it is going to implement the IQuoteProvider interface. The methods in the interface will be exposed.

Here is how the interface looks like.

 interface_1

Here is the class that serves quotes and implements the interface above

class_1  ‘

The assembly info contains the assembly guid

assembly_info

We need to make sure that a tlb file is generated and the assembly we created is registered. We will select “Register for COM interop” option from the build properties screen. See below …

build

2. VB6 Client Executable that uses the C# Library

We have created a simple VB6 application that refers and calls the C# assembly dll. See below:

VB6Client

Let compile the executable and it becomes VB6Client.exe

3. Unregister the C# COM dll to make sure that we a re not using the reference

We will use the following command line in the folder where the dll resides

regasm /u QuoteSource.dll

Lets run our VB6Client.exe and press the Get Quote button… walla! It does not work anymore. The executable exits with automation error since we unregistered it from windows registry.

4. Create the Application and Assembly Manifest and embed Assembly Manifest inside the QuoteSource.dll

First we are going to create an application manifest. The application manifest has to have the name in the format of exetutable full name + .manifest. Since our executable is called VB6Client.exe our application manifest will be called VB6Client.exe.manifest. Here are the contents of the manifest.

asm_manifest

Now lets create the assembly manifest and embed it inside out QuoteSource.dll. First we will create an xml file called QuoteSource.manifest. Please observe that we have put in the progid and clsid of the COM exposed class.

asm_manifest2

Now we need to convert this assembly into a resource file. We will use rc.exe that comes with windows SDK, or VC++ or VB6 installation.

We will create a text file called QuoteSource.rc  will put in the following line here.

1 24 QuoteSource.manifest

Here 1 is the manifest resource id and 24 means that it is a type of manifest resource. We will now invoke the Windows SDK resouce compiler from the command line. Check where in you computer you have the resource compiler installed. Here is the command line

rc.exe QuoteSource.rc 

After invoking this it will create a file called QuoteSource.res. This is a windows resource file.

Now we will use a custom build command to create the dll. Observe the command line below

csc /t:library /out:QuoteSource.dll /win32res:QuoteSource.res 

IQuoteProvider.cs QuoteProvider.cs Properties\AssemblyInfo.cs

See the win32res switch, it tells the compiler that it is a win32 resource.

Now copy the dll to the same folder as the exe, also copy the application manifest. There is no need to copy the assembly manifest as we have already embedded it inside the dll.

Run the the application and press the Get Quote button, it works!

5. XCopy Deployment

Copy or move the folder elsewhere, even to another computer. It will still work without any need to register the .NET COM dll. This is because we have created the application and assembly manifest and windows is treating our application as a Isolated application.

Last Words

This way you can create XCopy deployment for even COM based applications and avoid storing information in registry. Even a multi dll VB6 or VC++ application can be made Isolated Application.

kick it on DotNetKicks.com

Converting Typepad Exported Blog format to BlogML

My blog is hosted at Typepad, which in my personal opinion takes the least time to manage than any other blog hosting service. The payment option from typepad has no Paypal support as of the time of my writing and I did not want to spend from my card. So I planned to move from typepad to self hosting. However that situation was resolved with help of typepad and I am still in Typepad,the best managed blog service.

I was planning to use BlogEngine.NET, a .NET based blogging platform to host and it supports importing from BlogML. Typepad is a blog hosting service that is based on MovableType blogging platform. MovableType exports blog contents into a plain text based format. I searched around the internet for a tool that converts typepad format to BlogML. Unfortunately there was none. So I had to write a converter to convert the typepad format.

Gotcha!

After converting the the blog content to BlogML I just found out that there is a click once installer that comes with BlogEngine.NET 1.4.5 and the application do not start. After a little investigation I had figured that the location of the installer is no longer valid. I then had to add support to directly import into BlogEngine by calling their webservice. So if you are converting the typepad blog exported please use the code below.

Download, Source and Usage

Download Typepad2BlogMLBinary
Download Typepad2BlogML

Usage: Typepad2BlogML.exe -i:[input file] -mode:[blogml|service] -o:[output file] -s:[service address] -u:[username] -p:[password]

There are 2 application modes, one for converting into BlogML and another for uploading to BlogEngine via a webservice.

For converting to blog ML you should use something like this:

Typepad2BlogML.exe -i:mytypepadfile.txt -m:blogml -o:out.blogml

For importing into BlogEngine 1.4.5 use command line code like this:

Typepad2BlogML.exe -i:mytypepadfile.txt -m:service -s:http://www.myblog.com/api/BlogImporter.asmx -u:username -p:password


Preparing to move to BlogEngine.NET from Typepad

I have been blogging for over a year now and have been using www.typepad.com as my hosting provider. Typepad is a wonderful host but it does not accept payments via paypal and accepts only credit/debit card which I do not want to use at the moment. Also it is written in perl/cgi probably. The MovableTypes framework is a awesome but it requires perl/cgi. Since I work on the .NET platform mostly I wanted to add some functionality to the blog which I cannot do with typepad or MT. So I have selected BlogEngine.NET as the blogging framework and preparing to move there.

The site will look the same as I will use the same design as it is now. I am also writing a converter that exports from typepad export format to BlogML which the BlogEngine accepts. Typepad has been a superb blog host until recently. The ticket that I opened a few days ago is still unresolved without a reply. Sad!


WPF Kid Stuff: Extracting a Control Template

One of the design principles for WPF was to enable the developer decide the look and feel of the control and that resulted in the most versatile UI framework that can be customized in any way the developer wants. Previously there were many widgets for different languages and frameworks because their look could not be customized beyond the method the control builder provided. With the help of templates in WPF that has changed and that is why there are a lot less custom controls in WPF than the previous technologies. In order to customize something the end developer has to only modify the templates.

If we want to modify a the default look of a controls that is not controllable by the properties, the best way to do that is to extract the existing template of the control and change that. Manually we could open up Expression Blend and right click on a control end edit a copy of the template. See image below.

extract

This would actually reveal the control template that builds control and we can modify it and use as we please.

Another procedure is the extract the template from code is to get the template from the control itself. We can write c# code to extract the template like this …

// Get the template from the control ControlTemplate template = ctl.Template;
// We want our xaml of be properly indented, ohterwise
// we would not be able to indent them.
XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Indent = true;
// Make the string builder
StringBuilder sb = new StringBuilder();
XmlWriter writer = XmlWriter.Create(sb, xmlSettings);
XamlWriter.Save(template, writer);

// Now the sb.ToString() should give us the template

Note: There will be more controls in the xaml template output. Their templates can be extracted further.


Comparison of Different Open Source Licenses -“With Comparison Chart!”

I was a little confused with which license to use for an open source initiative and the benefits and limitations of difference licenses, so I dug a little and here is what I have found. I hope this helps you with your selection of a license for your open source initiative.

Pretext

Previously I had my open source projects listed in SourceForge.net, and the last one I worked on was pretty long ago. Recently I took on a few more initiatives to release some of the libraries that I developed as open source projects and a new open source project for file synchronization. As a .NET person my first choice was CodePlex.com which is a great site with TFS and subversion and issue tracking support.

I am used to write the license myself for the software. However the codeplex site comes with a bunch of pre defined standard licenses and no option to write your own custom open source license. In order select a license I had to read all of these licenses and also read this cool book on licenses - Open Source and Free Software Licensing By Andrew M. St. Laurent from O’Reilly press (ISBN: 0-596-00581-4).

The Licenses In Discussion

I am going to discuss the following licenses:

1. The MIT License
2. New BSD License
3. Apache License
4. Microsoft Public License (Ms-PL)
5. Microsoft Reciprocal License (Ms-RL)
6. GNU General Public License (GPL)
7. GNU Library General Public License (LGPL)
8. Common Development and Distribution License
9. Mozilla Public License 1.1 (MPL)

The Basis of Open Source Licensing

Open source does not mean free software, but often is associated with it. Some licenses makes the software free for use, some licenses are to make sure that source is always distributed with the binaries. There are 2 items common among all of these licenses. Firstly the license must be distributed with the software usually with both binary and source code form. Secondly, the licenses have a warranty disclaimer. Having a warranty disclaimer is very important when you are making a free software. Since software creator is not making money out of a software it does not make sense to be liable for implied warranty. The warranty disclaimer releases the creator of the software from the liability of implied warranty.

Comparison Summary

The chart below shows a basic comparison of explicitly stated items among different open source licenses (click to enlarge)

OpenSourceLicenseComparison

Hope this helps to have an overview of the licenses

Simple Licenses

The MIT License

The MIT License is the simplest non restrictive open source license. It has only two parts, at the first part lets anyone use the software for free even it lets anyone publish, distribute, sublicense or even sell copies of the software. The second part is the disclaimer for warranty.

New BSD License

The new BSD license is as unrestrictive as the MIT license except for the fact, it does not allow the name of the contributors to be used to endorse any derivative software.

Microsoft Public License (Ms-PL)

The Microsoft Public License is similarly non restrictive as the previous two with the following explicit notations. Firstly, the license does not grant permission to the contributor’s name, logo or trademark. Secondly this license lets you royality free use of contributor’s patents that are used in the software but if you make any patent claim against any part of the software your license to the use of contributor’s parent is revoked.

Microsoft Reciprocal License (Ms-RL)

This license exactly as same as the previous one except that if you use any file from software then you must provide source for those files and the copy of the license and the other files in the end result software can be licensed under any term you want.

Common Development and Distribution License (CDDL)

CDDL is also a non restrictive type of open source license, but it has a lot of items explicitly described. See license details

Apache 2.0 License

Apache license makes sure that the software is free, the name of apache foundation cannot be used to endorse the product, any change to the software needs to be distributed in source form and it lets you provide warranty if you want to.

So read the licenses now and select the one that you like.

Complex Licenses

GNU General Public License (GPL) 

This is a highly restrictive license and any software that uses this license must also be distributed under GPL which makes GPL quite infamous and at the same time favorite to a breed of developers. There are several gotcha clauses in GPL. I am not going to describe it as there are many points to discuss. Please read it carefully.

GNU Library General Public License (LGPL)

This is a better version of the GPL license aimed more at the software components. It lets you have LGPL license for the component to be used in software while other components can have different licenses.  Both the GPL and LGPL allows the open source software to be sold as long as the source code is provided. Please read the license carefully before selecting it.

Disclaimer

Firstly I am not a lawyer, and this is my understanding from what I have read in the licenses and there is no guarantee that what I am writing here is correct since this is my personal interpretation. I would advice you to read the  licenses before you apply them and I do not take any responsibility of my interpretation.

kick it on DotNetKicks.com

A very simple C# interview question that most developer fails

We interview a lot of people and usually go through at least 3 interviews to select someone for the organization I work in. A recent trend of new developers is baffling me. The newcomer to development do not seem to know any of the basics. These newcomers might know some Linq, Ajax and famous frameworks but they fail at very simple OOP questions and fairly have very little or no idea about the CLR.

Anyway that is not the topic that I was going to write today, I have seen good candidates fail at a this question, which is basic knowledge. I don’t know why but this simple question baffles a lot of people. So I have decided to ask the readers this question.

Question:

How do you define a property read only for the outside world and writable for the same assembly classes?

For example I have a class named User where everyone outside the assembly can read the string ‘Name’ property but cannot set it. However the classes inside the assembly is able to set the property.  I am further detailing the exlanation.

User myUser = SomeClass.GetUser();

// OK for all classes since all can read it
string name = myUser.Name;    

// This line does not compile if this code is 
// written in a class that is not in the same 
// assembly as the type User. But it compiles
// if the code is written in the same assembly
// that contains the type user.
myUser.Name = "C# Developer"; 

Answer:

Now all I want is the c# code declaration for the property name that matches my requirement of being read only for the outside world. Write it in the comments section. I will answer the question 24 hours from now.

kick it on DotNetKicks.com

Extend WPF: Add your own keywords and functionality to XAML with Custom Markup Extensions

WPF is highly customizable and flexible. Also what makes WPF even better is XAML, the markup based declaration language, which is often associated to WPF but not limited to it. I am pretty sure whoever is reading this post have already wrote few XAML based UI and many of the readers have created a full blown WPF application. We use many XAML extensions in our day to day applications. All of these extensions derive from the System.Windows.Markup.MarkupExtension class. We use extensions like StaticResource, DynamicResource etc in everyday Xaml.

The curly braces “{ }” notation tells the XAML processor that it has encountered an extension and the Xaml processor responds accordingly by evaluating the text inside the curly braces. Here is an example on how extensions are used.

<Window.Resources>
  <SolidColorBrush x:Key="mybackground" Color="#FF8080C8"/>
</Window.Resources>    
<Rectangle Height="84" Name="rect1" Width="162" 
Fill="{DynamicResource mybackground}" />

In the above sample we have declared a rectangle element and we taking the fill color dynamically from the ‘mybackgorund’ solid color brush which is defined within the windows resources. By taking approach this we can also use the same brush in other WPF elements.

Markup Extensions

MarkupExtension is the base class for any Xaml extension. Just like .NET attributes which ends the name with the word ‘Attribute’, the markup extensions end the class name with the word ‘Extension’. They should be used in Xaml syntax without the appended word ‘Extension’ just like attributes.

Extensions
The above diagram shows how extensions are inherited and how those classes are used with curly brace (“{ }” ) markups.

Custom Markup Extensions

XAML cannot do everything, and in any good application we need to write code. However if there are some code that are repetitive and we want to declare those code in XAML markup we can write our own markup extensions.  In order to do so we need to inherit from the abstract class System.Windows.Markup.MarkupExtension and implement the abstract method ‘ProvideValue’. See the signature of the provide value method below ...

public object ProvideValue(IServiceProvider serviceProvider)

Then we need to reference our namespace in Xaml and use the extension.

Relative Color Markup Extension : A Custom Extension example

There are many cares where we need to have a relatively lighter or darker color of a certain color. For example if we are designing a button and when the mouse moves over the button we want a lighter shade of the normal color of the button and when mouse is down we want a darker color. In order to do these things in XAML we would have to write triggers and 3 different colors. Lets assume we start with color blue and define blue, a lighter shade of blue and a darker shade of blue, then we would be in trouble if we decide to make our button green and have a light green, green and dark green color. We would have to change all 3 colors. Now wouldn’t it be nice if we could define one color and then have darker and lighter shade of it? If we decide to change color then we would have to change the base color only. See the example below

Colro Example

Writing the custom markup extension

Lets name the custom markup extension that we are writing as RelativeColor, so the class name has to be ‘RelativeColorExtension’.

[MarkupExtensionReturnType(typeof(Brush))]
public class RelativeColorExtension : MarkupExtension

Here our class inherits from MarkupExtension and we are explicitly declaring that the return value is a brush. The MarkupExtensionReturnType attribute lets you specify the return type. However this is optional. You might not want to declare that, specially where the return type determined at runtime and can vary.

Before we proceed further lets see and example of just how this extension will be written in Xaml so that we can better explain how we will write the extension.

XamlUser

The Styles

In our custom markup extension we have 3 styles, Lighten, Normal and Darken. We will specify the base color and which style to apply in the Xaml markup. So we define an enum in the custom extension class like this.

public enum MorphStyle
{
    Lighten, Normal, Darken
}

We need to define a property that will store this style

private MorphStyle _style = MorphStyle.Normal;
/// <summary>
/// Which style to render 
/// </summary>
public MorphStyle Style
{
    set { _style = value; }
}

The Reference Color

Since we need to refer to a color in the resource dictionary, we need to have a property for that as well.

private string _baseColorKey = null;
/// <summary>
/// This is the key of the reference color. This should be defined in a
/// dictionary 
/// </summary>
public string BaseColorKey
{
    set { _baseColorKey = value; }
}

In this variable the key (x:key attribute) of the reference color will be stored.

Overriding the ProvideValue

We simply have to override the ProvideValue method first like this.

/// <summary>
/// Overridden method returns the brush based on style and base color reference
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
public override object ProvideValue(IServiceProvider serviceProvider)

By the time this method is called the Xaml Processor have already set the two properties from our Xaml declaration ( we will see the Xaml declaration a little later in the post). So we have the resource key of the base color and how to render it. We are going to keep our resources in the Application resource file and load from there.

// Check if the key is valid
if (!string.IsNullOrEmpty(_baseColorKey))
{
    object obj = Application.Current.FindResource (_baseColorKey);
    if (obj != null)
    {
        coreColor = (Color)obj;
    }

Deciding based on the style

Since we have found the referenced color, we can create a lighter or a darker version of it. (Disclaimer: The code we used to get darker or lighter version of a color in the static methods DarkenColor and BrightenColor are very simple and basic and may be a very simple and lame implementation. This was done in order to keep the irrelevant code simple so that we can easily transfer the idea of custom markup extension to the reader). Since the style property of the extension was filled by the Xaml Processor we can act on their values. See code

// Lets return a solid color brush 
if (this._style == MorphStyle.Lighten )
{
    return new SolidColorBrush(BrightenColor(coreColor));
}
else if (this._style == MorphStyle.Normal)
{
    return new SolidColorBrush ( CopyColor (coreColor));
}
else
{
    return new SolidColorBrush(DarkenColor(coreColor));
}

Using our extension in Xaml code

Xaml is not a WPF specific markup language, but it is most widely used in WPF and silverlight. In WFP Xaml files start element you will find code that look like this ...

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Then we use x:Key and other “x” based namespaces because the it is generally imported under ‘x’ namespace . We have build our custom extension in a dll and we need to import that as a name space to our code.

Custom Namespaces in Xaml

In order to use classes from another dll in Xaml we will need to introduce a custom namespace. The format for defining a custom namespace looks like this

xmlns:namespace="clr-namespace:namespace;assembly=assemblyname"

In our case both the assembly name and the namespace is ‘MyXamlExtensions’ and the namespace that we will use is ‘ce’ which is a short for custom extension. So the entry for our custom extension will look like this in the root element of the Xaml document.

xmlns:ce="clr-namespace:MyXamlExtensions;assmebly=MyXamlExtensions"

We are going to import the namespace in the application resource file and define a style for a rectangle object

<Color x:Key="MyBackColor" R="#80" G="#80" B="#C8" A="#FF" />
<Style x:Key="ActiveRectangle" TargetType="{x:Type Rectangle}" >
  <Style.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
      <Setter Property="Fill" 
         Value="{ce:RelativeColor BaseColorKey=MyBackColor,Style=Lighten}"/>
    </Trigger>
    <Trigger Property="IsMouseOver" Value="False">
      <Setter Property="Fill" 
         Value="{ce:RelativeColor BaseColorKey=MyBackColor,Style=Normal}"/>
    </Trigger>
  </Style.Triggers>
</Style>

You can see in the above example that  we are referencing the ‘MyBackColor’ as a reference and using our markup extension without the word ‘Extension’ at the end and we are also setting the BaseColorKey and Style property. We have defined the style in a way so that a lighter shade of the color is assigned to the rectangle when mouse is over the rectangle at other time the normal shade is used. Also please notice that the properties are defined in the extension with comma separation. Now we will set the style to rectangle like this.

<Rectangle Height="93" Name="rectangle1" Stroke="Black" 
    Width="243" Style="{DynamicResource ActiveRectangle}" >

If we want to change the mouse over and normal colors we could just change the base color defined at ‘MyBackColor’.

Now that we have created an extension we can use it anywhere. We can write our common tasks in code and make them into extensions and re-use them in different Xaml markups.

Sample source code

You can download the custom markup extension code from from here. Have fun and let me know what extension did you make.

kick it on DotNetKicks.com

Make Google Chrome Take Less Memory

Earlier I wrote how chrome is taking huge amount of memory because it is running one process for each tab (http://www.shafqatahmed.com/2008/09/google-chrome-i.html). It seems that Chrome supports other process models as well. Here are the process models for Chrome browser

1. Process Per Tab (default model)

2. Process Per Site: One process per website. For example a user with two tabs opened at Gmail and another opened at facebook will have the two google tabs running in the same process. (default model)

3. Single Process ( walla! this is what I was looking for)

All this was cleared by blogger Marc Chung at his post Chrome's Process Model Explained. Right now I am running Chrome in a single process.

At the chrome shortcut pass the appropriate command like option to control Chrome’s behavior.

--process-per-site
--process-per-tab
--single-process

Here is how you edit the shortcut to run with different process model. Open up the properties tab of the Chrome browser short cut and edit it like the image below

single

So here I have 3 shortcuts to Chrome in my desktop. See the picture below

2008-09-07_1920

So now I can run chrome anyway I want. Chrome has become my second browser of choice after Opera. Chrome will occupy less memory now.


Google Chrome: I liked it at first but … its memory usage is ABSURD!.

Update: I am retracting my statement that Chrome takes huge memory and saying that Chrome takes huge memory by default. But you can change that by changing settings. See the update on Make Google Chrome Take Less Memory

There has been a huge ripple in the web since Google released the Chrome browser. At first I really liked chrome, specially its speed and ease of use. As a developer I work on Microsoft technologies and I like the services that Google provides. When Google and MS competes it is a win win situation for me, the consumer.

I am sure you have read many blog posts by now hearing praises of Chrome, and I would have sung praises too … but its memory usage is absurd.

My favorite browser is opera and I use a custom hand written configuration of Opera and I also use the Flock browser beta with the Firefox 3 engine. After using for a day or two I was kind of  thinking that Chrome would replace my use of Firefox.

I have a habit of of going through my daily list of articles in the Google reader and opening the new articles in different windows. By the time I am done selecting the items to read I have about 50 tabs open which is very easy in Opera. Unfortunately I was amazed at Chrome’s irresponsible memory usage. For each single open window or tab it at least has a process running.

Think again … one process for one tab. Are you nuts!!

Here is a screenshot of the tabs I had opened ( only 4 tabs )

2008-09-07_0147

Now take a look at the processes and memory usage by chrome

2008-09-07_0149

There are 7 processes running for those 4 tabs and taking 161 MB of RAM. I feel scared to even think about how much memory it would have occupied if I had opened 50+ tabs like I usually do.

Unless Google changes this model, I would stick to my good old Opera and Flock for heavy browsing.

kick it on DotNetKicks.com

Secure Yourself: Avoid Hackers & Keyloggers & all forms of malwares

Everyone now days knows the need to secure his computer with millions of virus and other forms of malware running amok on the internet. In this post I will try to recommend the tools that I use for securing myself.  By the way, if you have a Anti-virus running do not think that you are safe. Even if you have firewall running, still do not think yourself as safe. I have many security softwares running and I do not consider myself safe from harm. I am going to recommend a few software that I use in order to secure myself. Some of these are free and some are paid versions.

Antivirus

Avira Antivirus: I use Avira antivirus ( free-edition ) to protect myself from viruses. Avira is probably best free the fast anti-virus with very high detection rate (my opinion). I actually researched a little before selecting this as the anti-virus to  shield myself with. See my post on anti-virus selection : My quest to select a good Antivirus for the year 2008.

One downside of using Avira is the nag screen which itself looks like adware. Avira would pop up a screen a few times a week where it would advertise for its paid version. And that ad looks horrible.  Everything else is good. If you do not want the nag screen to be there then buy it. I did not.

By the way, Avira has already paid off, as I have been protected several times from virus attack by it.

Firewall

I have used Norton, Zone Alarm and all other crap firewall at point in my life. But for last few years I have switched to better firewalls. I use Outpost Security Suite which gives me superb granular control over the network access of my computer. But before I discuss that I would like to point to the one below

Comodo Firewall Pro (Freeware): Comodo is a free online security company which sells SSL certificates, Identity Projection etc. They give you a barrage of free security softwares which includes free firewall, free anti-malware and  free anti-virus. Now that is what I call a deal, you cant beat free! I have not tried their anti-virus or the anti-malware but I have used their firewall for almost a year and it is rock solid. At that time only outpost had anti leak support. Comodo was the other firewall that gave such detailed control. Now if you are someone who wants to see what is going on at your network then this the the firewall for you.

Check this out: Screenshots of Comodo Firewall Pro running.

Now you might be be thinking … what is their business model and why am I getting a free firewall that is so awesome. This is what they are saying at their web site

You must be wondering - how can we stay in business by giving away high quality solutions that all other software vendors sell. Simply, Comodo's main revenue comes from authenticating web business with SSL certificates (e.g. we put the padlock on websites).

Outpost Security Suite (Not Free): I was instantly in love with the Outpost Firewall. Later on I decided to buy the security suite they provided. And I am still using it. It is so far the best firewall I have seen. Outpost monitors everything – and by everything I mean everything there is to be monitored. It can run in a very easy mode for a novice user or a very secure highly detailed mode for the advanced user.

It has 3 level of rules, Low Level Rules, Global Rules and then the Application rules. You can modify each. It has superb host projection and critical system components like registry and startup items protection. Here are a few screen shots of the host protections configurations screen and the web control configuration screen and finally the application configuration screen. 

outpost outpost2 outpost3

Also outpost has extremely powerful network connections and log views.

Outpost is my first choice, but if you do not want to spend money then you still have option to use Comodo.

Anti Keylogger

Even after you have used anti-virus and firewall software there could be unknown malwares hidden in your PC (outpost detects keylogging attempts usually). Someone could have written a custom keylogger software that no anti-virus would be able to detect. Such event could be your worst nightmare. Not only the hacker will have access to you computer password but he may have your office email passowrd, your personal email password, your credit card number, your paypal account password, your facebook password etc. Think of what would your life if someone has those and used your logins for his benefits. So it is best to have anti keylogging software installed.

Keyscrambler (Free and Paid): KeyScrambler is a software that installs as a kernel mode driver and encrypts the keyboard strokes and decrypts them at the application that you are using. So any keylogger software that is trying to get a hold of the keystrokes will have a set of scrambled meaningless junk.

The free edition of Keyscrambler support IE, Flock and Firefox browser and that should take of most of you. However I use Opera as my primary browser, and flock as secondary browser and do not use IE at all, so had to buy the paid version to support Opera and the messenger softwares like, MSN, GTalk, Yahoo, Skype. The paid version also supports outlook, thunderbird, office applications.

VPN Service

When ever you are using internet on a non secured connection a hacker might intercept the data and steal you data and passwords. Also your ISP can track what site you are visiting, they can see your email messages and IM chat text if they want to. However you can avoid this unsecured scenario with a VPN service. When you are connected to a VPN connection the data is encrypted and cannot be decrypted. There are many VPN services available. When you connect to these VPN service the data is decrypted at the VPN server and sent from there, so no one can track your internet footprint.

I use a 1 year VPN service from a commercial VPN provider and when ever I access sensitive information I connect to the VPN service. One cool thing about this provider was access to Pandora music web site. Pandora only allows you to listen if you are in the US. Since the VPN service is at US, when I connect to it, it detects my location to be in US and lets me listen to songs.

Password Manager & Encrypted Disk (Freeware)

KeePass: There are several password managers available but I use KeePass, an open source password manager which seemed most advances and robust. Try it.

keepass

True Crypt: I also use TrueCrypt to mount a drive where I can store all my sensitive data in encrypted format. Truecrupt is also a free open source application. One good feature in TrueCrypt is plausible deniability. You can create hidden volumes within a TrueCrypt volume where you will store the real sensitive data and in the outer volume you can store some sensitive looking files. If someone tortures you and asks you for password then you can tell them the password to the outer volume and they will think you have given the abductor the right password.

FreeOTFE: For storing sensitive data one windows mobile phones you can use Free OTFE which lets you have encrypted drive in a windows mobile phone.

Conclusion

I hope this post have been helpful to solve your security problems.