Class_Terminate emulation

  • Thread starter Michael D. Ober
  • Start date
M

Michael D. Ober

Is there anyway to force the equivalent to VB 6's Class_Terminate event when
a class object goes out of scope. I have several classes in VB 6 that
depend on the Class_Terminate event firing as soon as the class variable
goes out of scope and need to be able to duplicate this functionality in VB
2005.

Thanks,
Mike Ober.
 
T

Tom Shelton

Is there anyway to force the equivalent to VB 6's Class_Terminate event when
a class object goes out of scope. I have several classes in VB 6 that
depend on the Class_Terminate event firing as soon as the class variable
goes out of scope and need to be able to duplicate this functionality in VB
2005.

Thanks,
Mike Ober.

The closest you can can get is to implement Dispose. Here is a
reference to the general pattern:

http://msdn.microsoft.com/library/d.../en-us/cpgenref/html/cpconFinalizeDispose.asp

Once you have that, in VB.NET 2005 you can use the using statement (like
c#) to sort of fake deterministic finalization...

Using theVariable As New TheClass ()
'Do Stuff with theVariable
End Using

Dispose will automatically be called when you hit the end of the using
block - even if it is due to an exception. In versions previous to
2005, you would have to do something like:

Dim myVariable As New TheClass
Try
' do stuf with myVariable
Finally
myVariable.Dispose ()
End Try

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top