*Experts* Merrion Posted July 15, 2003 *Experts* Posted July 15, 2003 Alright - a bit of thinking outside the box needed here - I want an application wide number that I can increment every time I create a new isnatnce of a particular class. It needs to be thread-safe as well - any thoughts? Merci en avance, Le Duncan Quote Printer Monitor for .NET? - see Merrion Computing Ltd for details
*Experts* Volte Posted July 15, 2003 *Experts* Posted July 15, 2003 You could make the variable a publically Shared/static one of the class you are talking about (meaning, of course, that you can access it without needing an instance of the class). Then you just increase it in the constructor and decrease it in the destructor. Much like the way COM classes work with AddRef and Release. Public Class MyClass Public Shared refCount As Integer Public Sub New() refCount += 1 End Sub Protected Overrides Sub Finalize() MyBase.Finalize() refCount -= 1 End Sub End Class Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.