By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,160 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,160 IT Pros & Developers. It's quick & easy.

Class_Terminate emulation

P: n/a
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.

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <eg**************@tk2msftngp13.phx.gbl>, Michael D. Ober wrote:
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/de...izeDispose.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
--
Tom Shelton [MVP]
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.