Tuesday, January 13, 2009

Step1.
To create a new Window Service, pick Windows Service option from your Visual C# Projects, give your service a name, and click OK.
This action will add WinService1.cs class to your project.
Set your ServiceName to your own name so it would be easier to recognize your service during testing OR you can set this property programmatically using this line this.ServiceName = "MyWinService";Step 2. Add functionality to your service
The default code of WebService1.cs added will have two overridden functions OnStart and OnStop. The OnStart function executes when you start your service and the OnStop function gets execute when you stop a service. I write some text to a text file when you start and stop the service.

Step 2.5.
a) Return to Design view for WinService1.
b) Click the background of the designer to select the service itself, rather than any of its contents.
c) Right click on the Designed Windows and in the Properties window, click the Add Installer link in the gray area beneath the list of properties.
d) By default, a component class containing two installers is added to your project. The component is named ProjectInstaller, and the installers it contains are the installer for your service and the installer for the service's associated process.
e) Access Design view for ProjectInstaller, and click ServiceInstaller1. In the Properties window, set the ServiceName property to MyNewService. Set the StartType property to Automatic.
f) In the designer, select ServiceProcessInstaller1 (for a Visual Basic project), or serviceProcessInstaller1 (for a Visual C# project). Set the Account property to LocalService. This will cause the service to be installed and to run on a local service account.
After the above procedure, try registering using InstallUtil utilities.

Step 3: Install and Run the ServiceBuild of this application makes one exe, MyWinService.exe. You need to call installutil to
egister this service from command line.
installutil C:\mcWebService\bin\Debug\mcWebService.exe
You use /u option to uninstall the service.
installutil /u C:\mcWebService\bin\Debug\mcWebService.exe
Run the application

Step 4: Start and Stop the Service
You need to go to the Computer Management to start and stop the service. You can use Manage menu item by right clicking on My Computer.
Under Services and Applications, you will see the service MyWinService. Start and Stop menu item starts and stops the service.
Go to your temp directory and see if text file is there with contents or not.
That's it.

Both delegates and interfaces allow a class designer to separate type declarations and implementation. A given interface can be inherited and implemented by any class or struct; a delegate can created for a method on any class, as long as the method fits the method signature for the delegate. An interface reference or a delegate can be used by an object with no knowledge of the class that implements the interface or delegate method. Given these similarities, when should a class designer use a delegate and when should they use an interface? Use a delegate when: • An eventing design pattern is used. • It is desirable to encapsulate a static method. • The caller has no need access other properties, methods, or interfaces on the object implementing the method. • Easy composition is desired. • A class may need more than one implementation of the method. Use an interface when: • There are a group of related methods that may be called. • A class only needs one implementation of the method. • The class using the interface will want to cast that interface to other interface or class types. • The method being implemented is linked to the type or identity of the class: for example, comparison methods. One good example of using a single-method interface instead of a delegate is IComparable or IComparable. IComparable declares the CompareTo method, which returns an integer specifying a less than, equal to, or greater than relationship between two objects of the same type. IComparable can be used as the basis of a sort algorithm, and while using a delegate comparison method as the basis of a sort algorithm would be valid, it is not ideal. Because the ability to compare belongs to the class, and the comparison algorithm doesn’t change at run-time, a single-method interface is ideal.

Thursday, January 8, 2009

Advantages of Using Globally Unique Identifier (GUID) as a Primary Key Advantages:
■ If you use an auto-number Id column and if many people are creating new DataRow objects, it will be difficult for you to merge data later because there may be many duplicate keys.

■ The Guid data type is a “surrogate” key, meaning that its only purpose is to define uniqueness of the row and aid in connecting multiple tables together via relationships. This means that there is no reason for a user to see and change this value, which simplifies maintenance of the DataSet. If you allow the user to change the primary key on a row, you have to propogate the change down to all of the related tables. For example, changing the CompanyId value requires the update of the Company Id value in the Employee table.

■ The use of the Guid can simplify the joining of tables, which is better than the scenarios where you use compound keys that are based on the actual data. Compound keys typically result in smaller data footprints because the key is based on actual data, whereas joining tables is usually more difficult because compound joins are required. Remember that if you are using compound keys that are based on the actual data, you inevitably need to deal with recursive updates.

The first thing that most Javascript programmers end up doing is adding some code to their program, similar to this:
window.onload = function(){ alert("welcome"); }
Inside of which is the code that you want to run right when the page is loaded. Problematically, however, the Javascript code isn't run until all images are finished downloading (this includes banner ads). The reason for using “window.onload” in the first place is due to the fact that the HTML 'document' isn't finished loading yet, when you first try to run your code.
To circumvent both problems, here comes jQuery...Write Less, Do More, JavaScript Library.