How do i force the dispose method to be called automatically, DOT NET Programming

How do I force the Dispose method to be called automatically, as clients can forget to call Dispose method?

To Call the Dispose method in the Finalize method and in the Dispose method suppress the finalize method using GC.SuppressFinalize. The sample code of the pattern is shown below. This is the best way we do clean our unallocated resources and yet not to forget we do not get the hit of running the Garbage collector twice.

Note:- It will suppress the finalize method thus avoiding the two trip. 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

Posted Date: 9/22/2012 3:23:45 AM | Location : United States







Related Discussions:- How do i force the dispose method to be called automatically, Assignment Help, Ask Question on How do i force the dispose method to be called automatically, Get Answer, Expert's Help, How do i force the dispose method to be called automatically Discussions

Write discussion on How do i force the dispose method to be called automatically
Your posts are moderated
Related Questions
i am working on an project and my client needs it in 2 days.project is ready but don''t know how to make setup project including local sql database(.mdf) included in setup..

What are the four workflow principles? According to Microsoft, there are four main principles that define the behavior and working of workflows. Developers can use these princi

Project Description: I am seeking software that can do the subsequent: 1. Check position for a URL in Google, Bing, Yahoo. 2. Check position for a Youtube video in Youtube

What is the difference between DELETE TABLE and TRUNCATE TABLE commands? Following are differences between delete & truncate commands:- 1)The DELETE TABLE syntax logs the de

Explain Component diagrams Package: - The Package logically make group of element of a UML model. Component: - It is the actual physical module or implementation of

What is the difference between OLEDB Provider and SqlClient? With respect to usage, there is no difference among OLEDB Provider and SqlClient. The dissimilarity lies in their p

The ADO.NET gives the SqlCommand object which gives the functionality of executing the stored procedures. CREATE PROCEDURE SelectByEmployee @FirstName nvarchar(200) AS Se

What is a host process? A host process is an implementable program that hosts a workflow. It might be a Windows Forms application, a Web application, or a Web service applicati

GAC (Global Assembly Cache) is used where shared .NET assembly resides.Global Assembly Cache is used in the following situations:- 1) When the application has to be shared among

Name the classes that are introduced in the System.Numerics namespace. The following two new classes are introduced in the System.Numerics namespace:  BigInteger - Refers