Pages

Tuesday, July 6, 2010

Dispose method and Finalize method

Finalize Method: As .net provides a great feature of memory management which handles all kind of allocations and de-allocations automatically and for de-allocating it uses Garbage Collector. So in .NET Garbage collector does almost all clean up activity for your objects. But all the process that can happen for de-allocation is applicable only that are managed by CLR or that are constructed according to the .Net but those object that are not managed by .Net CLR are un-managed codes/objects can not be de-allocated directly by GC So these unmanaged resources (ex: - Windows API created objects, File, Database connection objects, COM objects etc) that are outside of the scope of .NET framework are needed to be cleaned explicitly. For these types of objects .NET framework provides Object.Finalize method which can be overridden for our own code execution within this function and which can be used to clean up code for un-managed resources. This method is used in VB.Net which is called by CLR when Garbage Collector destroys an object. While in C# destructors are there for the same purpose.

Dispose Method: .NET provides “Finalize” method in which we can clean up our resources. But relying on this is not always good. This is because it is only called by the GC and you can't determine when it will be called (even though you can force it to be called, but that's not recommended).So the best is to implement “Idisposable” interface and implement the “Dispose” method where you can put your clean up routines.

But benefit of finalize over Dispose is that finalize is executed itself and not required to be called while Dispose is required to be called. So in case we require to execute dispose itself then we can call it within finalize which is executed by CLR while destroying the object. But in case we define call dispose this way also developer called dispose too at somewhere then call dispose can occur twice that can throw exception or some issue so to avoid call twice we can suppress the call to finalize after dispose by using GC.SuppressFinalize within dispose function some in that case if dispose is not called then it will be executed with finalize while if its called then suppressfinalize call will suppress the call to finalize method. Below is the sample code of the pattern. This is the
best way we do clean our unallocated resources and yes not to forget we do not get the hit
of running the Garbage collector twice in this case.


Note:- It will suppress the finalize method thus avoiding the two trip.
Publish Post


Public Class ClsTesting
Implements IDisposable
Public Overloads Sub Dispose()Implements IDisposable.Dispose
' write ytour clean up code here
GC.SuppressFinalize(Me)
End Sub
Protected Overrides Sub Finalize()
Dispose()
End Sub
End Class

Abstract Class And Interface Class

Interface Class: Its some kind of contract between developer/Class implementation and real world/caller of class object that commits what kind of the provisions will be their that can be accessed from the class implementation and also implementation is bound to provide the implementation of this contract.

Abstract Class: Its also define some kind of contract that a implementing class signs and bound to implement all the abstract functions for which no implementation is provided in the abstract class. So outer world of implementing class have knowledge of all the provisions and availability of functionality that can be called directly from the object of implementer class.

Benefit of Interface over Abstract class: As from the definition of the abstract class question arises that when everything that an Abstract class enforce or provide then why concept of Interface still exists the most well known answer of this question comes while an implementing class comes to the situation when it has to implement more than one kind of contracts to the outer world which makes the requirement of multiple inheritance which is not possible in case of abstract class as an implementer class can not implement more than one abstract class but it can implement more than one Interface.

Benefit of Abstract class Over Interface: Both seems to be related to contract between object calling and class providing implementation of interface. Also in case of existence of interface class an additional benefit it also facilitate with the feature of multiple inheritance then why abstract class exists. Answer to this query comes from abstract class's another feature that says if some of the implementation that is known and predefine also is common and usable in derived classes too then in case of abstract class we can implement this functionality in abstract class itself that will be available with all the derived classes which is not possible with usage interfaces.

If there is any other difference/benefit for these then I request to viewers to add their comments that can be beneficial for other viewers too.

Thursday, May 27, 2010

SQL Query: Second Maximum/Second Minimum

Tip to find the first max/min is predefined but what about second. Here is one of the tip for well known table employee

Second maximum salary
Select max(salary) from employees where regid NOT IN
(Select max(salary) from employees)

Second minimum salary
Select min(salary) from employees where regid NOT IN
(Select min(salary) from employees)

Wednesday, March 24, 2010

Visual Studio 2010 .Net Framework 4.0 Some of the enhavements

Following are some of the Visual Studio 2010 and .NET Framework 4 IDE Enhancements
1. Multi monitor support
2. Multi targeting
3. Parallel Development
4. Side by Side execution
5. Backward compatibility and SqlServer 2008 integration.
6. Add Reference enhancements for developers
7. Windows 7 support for developers
8. Share Point 2010 enhancements
9. Office Business Application Support
10. Cloud Development
11. Document Map Margin and Visual Studio 2010 Tips.

Following are some of the applications we can develop using the .NET Framework 4.0.

* Console Applications
* Windows Forms applications
* Windows Services
* WPF Browser applications
* WPF Applications
* Web Applications
* Web Services, Ajax enabled Web Services
* Dynamic Data entities Web Applications
* Dynamic data LINQ to SQL Web Applications
* Office Applications
* Reporting applications like crystal reports
* Cloud Services using Windows azure tools
* SharePoint projects, Business Data Connectivity model and workflow applications
* Sliverlight applications
* WCF Services, Ajax enabled WCF services
* Workflow console and workflow service applications
* CLR Console applications using VC++
* MFC and win32 applications
* Data Tier Applications and advanced database applications.


Refernce

Monday, March 22, 2010

MS SQL server name and instance name

Open the run command and type "sqlcmd" and press enter will open the related console and to get the server name and instance name, enter the following command in the command prompt

select @@servername
go
Also, connection string can be verified by entering the following command in the 'Run' window from windows start

sqlcmd -S Server\Instance

where server is the name of the server running Sql server and Instance is the name of the instance running on the server.

Refernce:
How to: Identify a SQL Server Express Instance

Monday, October 12, 2009

What are implicit objects?

What are implicit objects?

To simplify code in expressions and scriptlets, we can use automatically defined variables, called implicit objects.

1)out JspWriter
2)Request HttpServletRequest
3)Response HttpServletResponse
4)session HttpSession
5)page Object
6)PageContext PageContext
7)Application ServletContext
8)Config ServletConfig
9)Exception JspException

Monday, March 9, 2009

Internet Message Header Fields

The following is the list of the header fields that may be used in a mail header, so these can be parsing fields that may be needed to search to create a needed parser for the header.


Header field name Description
Abuse-Reports-To E-mail address for reporting abuse
Also-Control Usenet control message and a normal article at the same time
Alternate-Recipient Controls whether the message may be forwarded to alternate recipients
Apparently-To Recipients derived from message envelope when there is no To header
Approved Moderator of the Usenet newsgroup, or marks certain control messages
Approved-By Moderator of a mailing list, who approved the message
Article-Names Reference to specially important articles for a particular Usenet newsgroup
Article-Updates Similar to Supersedes but does not cause the referenced article to be physically deleted
Autoforwarded Has been automatically forwarded
Auto-Forwarded Misspelling of Autoforwarded
bcc Recipient(s) not to be disclosed to other recipients ("blind carbon copy")
cc Secondary, informational recipient(s)
Comments Text comments added to the message
Content-Alias Used in addition to Content-Location if this content part can be retrieved through more than one URI
Content-Alternative Information on where an alternative variant of this document might be found
Content-Base Base to be used for resolving relative URIs within this content part
Content-Class Type information of the content in some class hierarchy
Content-Conversion Whether the body may be converted from a charset to another
Content-Description Description of a particular body part of a message
Content-Disposition Whether MIME body part is to be shown inline or as an attachment; may also suggest a file name
Content-Features More detailed information about the Content-Type
Content-ID Unique ID of one body part of the content of a message
Content-Identifier A text string which identifies the content of a message
Content-Language Code for natural language used in the message
Content-Length Size in bytes of the message text
Content-Location URI with which the content of this content part might be retrievable
Content-MD5 Checksum of content
Content-Return Whether the content of a message is to be returned with non-delivery notifications
Content-SGML-Entity Information about the SGML entity declaration corresponding to the body
Content-Transfer-Encoding Coding method used in a MIME message body
Content-Type Data type and format of content
Control On Usenet, indicates a control message
Conversion Whether the body may be converted from a charset to another
Conversion-With-Loss Whether the body may be converted from a charset to another if information will be lost
Date The time when the message was written (or submitted)
Delivered-To Used for loop detection
Delivery-Date The time when a message was delivered to its recipient
Discarded-X400-IPMS-Extensions X.400 IPM extensions which could not be mapped to Internet mail format
Discarded-X400-MTS-Extensions X.400 MTS extensions which could not be mapped to Internet mail format
Disclose-Recipients Controls whether recipients are to be told the names of other recipients
Disposition-Notification-Options Options for notifications to be sent when the message is received
Disposition-Notification-To Requests for notification when the message is received, and specifies the address for them
Distribution Limitation on where the Usenet article can be distributed
DL-Expansion-History-Indication Trace of distribution lists passed
Encoding Mixed usage: content type encoding, length, or boundary information
Errors-To Address to which notifications are to be sent and a request to get delivery notifications


Expires Suggested expiration time
Expiry-Date Time at which a message loses its validity
Fax Fax number of the originator
Fcc Name of file in which a copy of the message is stored
Followup-To Usenet group(s) to which followups to the article should be sent
For-Approval Primary recipients, who are requested to approve the information in this message or its attachments
For-Comment Primary recipients, who are requested to comment on the information in this message or its attachments
For-Handling Primary recipients, who are requested to handle the information in this message or its attachments
From Author(s) or person(s) taking responsibility for the message
Generate-Delivery-Report Whether a delivery report is wanted at successful delivery
Importance A hint from the originator to the recipients about how important a message is
In-Reply-To Reference to message which this message is a reply to
Incomplete-Copy Body parts are missing
Injector-Info Information about article's injection to Usenet
Keywords Keywords to be used as an aid in determining if the message is interesting to the reader
Language Code for natural language used in the message
Lines Number of lines in the body of the message
List-Archive URL to use to browse the archives of the mailing list
List-Digest URL to use to subscribe to the digest version of the mailing list
List-ID URN of the the mailing list expander
List-Owner URL to use to send E-mail to the owner of the mailing list
List-Post URL to use to post to the mailing list


List-Software Information about the software uses in the mailing list expander
List-Subscribe URL to use to subscribe to the mailing list
List-Unsubscribe URL to use to unsubscribe the mailing list
List-URL URL for various information about the mailing list
Mail-Copies-To Special address for copies of posted followups
Mail-Reply-Requested-By Address to which notifications are to be sent and a request to get delivery notifications
Mail-System-Version Client software used by the originator
Mailer Client software used by the originator
Mailing-List Information about mailing list
Message-ID Unique ID for the message
Message-Type Indicates that this is a delivery report gatewayed from X.400
MIME-Version Specifies the version of MIME that the message format complies with
Newsgroups Usenet group(s) to which the article was posted
NNTP-Posting-Date Time of posting to Usenet
NNTP-Posting-Host Host that posted the article to Usenet
NNTP-Posting-Time Time of posting to Usenet
NNTP-Proxy-Relay Host that relayed the message to Usenet
Obsoletes Reference to previous message being corrected and replaced
Organization The organization to which the sender belongs, or to which the machine belongs
Original-Encoded-Information-Types Which body part types occur in this message
Original-Recipient Original recipient information for inclusion in disposition notifications
Originating-Client Client software used by the originator
Originator Used the same way as Sender
Originator-Info Information about the authentication of the originator
Path List of MTAs which the (Usenet) message has passed
Phone Phone number of originator
PICS-Label Ratings label to control selection (filtering) of messages according to the PICS protocol
Posted-To Newsgroup to which the message has been posted /td>
Precedence Mixed usage: priority value, control of automatic replies or return-of-content faciliries, prevention of mailing list loops
Prevent-NonDelivery-Report Whether non-delivery report is wanted at delivery error
Priority Priority for message delivery
Read-Receipt-To Address to which notifications are to be sent and a request to get delivery notifications
Received Trace of MTAs which the message has passed
References In E-mail: reference to other related messages; in Usenet: reference to replied-to-articles
Replaces Specifies previous message being corrected and replaced
Reply-By Latest time at which a reply is requested
Reply-To Suggested E-mail address for replies
Resent-bcc The bcc of a forwarded message
Resent-cc The cc of a forwarded message
Resent-Date The Date of a forwarded message
Resent-From The From of a forwarded message
Resent-Message-ID The Message-ID of a forwarded message
Resent-Reply-To The Reply-To of a forwarded message
Resent-Sender The Sender of a forwarded message
Resent-Subject The Subject of a forwarded message
Resent-To The To of a forwarded message
Return-Path Data passed from MAIL FROM: envelope
Return-Receipt-Requested Address to which notifications are to be sent and a request to get delivery notifications
Return-Receipt-To Address to which notifications are to be sent and a request to get delivery notifications
See-Also References to related articles (other than precursors) in Usenet
Sender The person or agent submitting the message to the network, if other than shown by the From header
Sensitivity How sensitive it is to disclose this message to other people than the specified recipients
Speech-Act Speech act categorization of the message
Status Status of delivery for the message when stored
Subject Text that provides a summary, or indicates the nature, of the message
Summary Short text describing a longer article
Supersedes Specifies previous message being corrected and replaced
Telefax Fax number of the originator
To Primary recipient(s)
Translated-By Mailbox of the person who made the translation
Translation-Of Reference to a message which the current message is a translation of
User-Agent Client software used by the originator
X-Abuse-Info Information for reporting abuse
X-Accept-Language Language preference(s)
X-Admin E-mail address of news server administration
X-Article-Creation-Date Time of original creation of the article
X-Attribution The name under which the sender would like to appear in attributions when the message is quoted
X-Authenticated-IP Apparently the IP address of the host of the sender
X-Authenticated-Sender Apparently some identification of the sender
X-Authentication-Warning Some warning
X-Cache Information about caching server software
X-Comments Comments, usually some disclaimer
X-Complaints-To An E-mail address for sending complaints on the adequacy of the Usenet message
X-Confirm-reading-to Address to which notifications are to be sent and a request to get delivery notifications
X-Envelope-From Sender, as extracted from the envelope
X-Envelope-To Recipient, as extracted from the envelope
X-Face Picture of sender's face (a 48×48 bitmap)
X-Folder Folder for saving the message
X-Http-Proxy Information about using Deja for posting, including the sender's IP address
X-Http-User-Agent Web browser used for posting
X-IMAP UID as defined in IMAP
X-Last-Updated Time of most recent update
X-List-Host As List-Software
X-Listserver As List-Software
X-Loop Used for loop detection
X-Mailer Client software used by the originator
X-Mailer-Info URL for info about client software used by the originator
X-Mailing-List Information about mailing list
X-MIME-Autoconverted Information about conversion of this message on the path from sender to recipient
X-MimeOLE Information about client software used by the originator
X-MIMETrack Info about the message passing through a router
X-MSMail-Priority Yet another priority indication
X-MyDeja-Info Internal user id
X-Newsreader Cient software used by the originator
X-NNTP-Posting-Host Posting host
X-No-Archive Do not archive the message in publicly available archives
X-Notice A comment on reporting abuse
X-Orig-Message-ID Original Message-ID
X-Original-Envelope-From E-mail address of original sender
X-Original-NNTP-Posting-Host Name or IP address of the original posting host
X-Original-Trace Information (host, time, etc.) about the original posting
X-OriginalArrivalTime Time when the message was delivered into the message transport system
X-Originating-IP Apparently the IP address of the host of the sender
X-PMFLAGS Internal flags indicating message status
X-Posted-By Attempted identification of the sender
X-Posting-Agent Client software used by the originator
X-Priority Priority for message delivery
X-RCPT-TO Indication of recipient on the SMTP envelope
X-Report Information about reporting abuse
X-Report-Abuse-To Information about reporting abuse
X-Sender Used similarly to Sender but often indicating that you may not be able to send E-mail to this address
X-Server-Date Some time denotation
X-Trace Information about posting
X-UIDL Unique ID for the message, local to a particular local mailbox store
X-URI Sometimes used with the same meaning as Content-Location, sometimes to indicate the Web home page of the sender or of his organisation
X-URL Similar usage as X-URI
X-X-Sender Similar to X-Sender
X400-Content-Return Possible future name for Content-Return
Xref Identification of a message within a server