C
cj
Stephany Young provided me with the following code to count threads
created by my program.
Public Class MyThreadCount
Private Shared m_lock As New Object
Private Shared m_threadcount As Int32 = 0
Public Shared Sub Increment()
SyncLock (m_lock)
m_threadcount += 1
End SyncLock
End Sub
Public Shared Sub Decrement()
SyncLock (m_lock)
m_threadcount -= 1
End SyncLock
End Sub
Public Shared ReadOnly Property ThreadCount() As Int32
Get
Dim _count As Int32
SyncLock (m_lock)
_count = m_threadcount
End SyncLock
Return _count
End Get
End Property
End Class
I use it by calling
mythreadcount.increment
mythreadcount.decrement
label1.text=mythreadcount.threadcount
Everything works great but I'm wondering how it gets started. I mean
how is it loaded I guess. why doesn't it need me to instigate it or
whatever. how does it know when to assign the variable m_threadcount to
0 on the very first time a sub in the class is referenced?
created by my program.
Public Class MyThreadCount
Private Shared m_lock As New Object
Private Shared m_threadcount As Int32 = 0
Public Shared Sub Increment()
SyncLock (m_lock)
m_threadcount += 1
End SyncLock
End Sub
Public Shared Sub Decrement()
SyncLock (m_lock)
m_threadcount -= 1
End SyncLock
End Sub
Public Shared ReadOnly Property ThreadCount() As Int32
Get
Dim _count As Int32
SyncLock (m_lock)
_count = m_threadcount
End SyncLock
Return _count
End Get
End Property
End Class
I use it by calling
mythreadcount.increment
mythreadcount.decrement
label1.text=mythreadcount.threadcount
Everything works great but I'm wondering how it gets started. I mean
how is it loaded I guess. why doesn't it need me to instigate it or
whatever. how does it know when to assign the variable m_threadcount to
0 on the very first time a sub in the class is referenced?