how do i force the dispose method to be called


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

Request for Solution File

Ask an Expert for Answer!!
DOT NET Programming: how do i force the dispose method to be called
Reference No:- TGS0161278

Expected delivery within 24 Hours