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
Ask queyuyuystion #Minimum 100 words accepted#

What is Multi-tasking? It is a feature of the modern operating system with which we can run multiple programs at the same time for example Word, Excel etc.

Project Description: The website should be CMS based; coding done only on ASP, MySql databases, .net script, aspx and java use with least of the flash work. We will be sharing j

Compute Average of 3 numbers - C# Program I didn't know the exact code for computing average of integer number. Can anybody suggest me the correct way for find out the average

Name the control that exposes the LINQ features to Web developers through the ASP.NET data-source control architecture. The LinqDataSource control exposes the LINQ features to

How can we load multiple tables in a DataSet ? objCommand.CommandText = "Table1" objDataAdapter.Fill(objDataSet, "Table1") objCommand.CommandText = "Table2"

Windows Phone 8 camera streaming to desktop app Project Description: I require WP8 application (client) that will: 1. Automatically evaluate and connect to Windows desktop

What's the difference b/w Unit testing, Assembly testing and Regression testing? The Unit testing is also known as the Component testing. The Unit testing ensures that the reli

Describe the EventLog class. The EventLog class is used to access the Windows event logs from Windows services. Using EventLog, you can also customize Windows event logs that r

Reflection All .NET assemblies have metadata information stored  the types defined in the modules. And This metadata information can be accessed by mechanism called as "Reflect