本文介绍了试图理解课程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Stephany Young向我提供了以下代码来计算我的程序创建的线程 。 Public Class MyThreadCount 私有共享m_lock作为新对象 私有共享m_threadcount为Int32 = 0 公共共享子增量() SyncLock(m_lock) m_threadcount + = 1 结束SyncLock 结束子 公开共享子减量() SyncLock(m_lock) m_threadcount - = 1 结束SyncLock 结束Sub 公共共享ReadOnly属性ThreadCount()如Int32 获取 Dim _count为Int32 SyncLock (m_lock) _count = m_threadcount 结束SyncLock 返回_count 结束获取 结束物业 结束课程 我通过致电 mythreadcount.increment 使用它mythreadcount.decrement label1.text = mythreadcount.thr eadcount 一切都很好,但我想知道它是如何开始的。我的意思是 我猜是怎么加载的。为什么不需要我煽动它或 无论如何。在第一次引用类中的子类时,它如何知道何时将变量m_threadcount赋值给 0? 解决方案 Stephany Young provided me with the following code to count threadscreated by my program.Public Class MyThreadCountPrivate Shared m_lock As New ObjectPrivate Shared m_threadcount As Int32 = 0Public Shared Sub Increment()SyncLock (m_lock)m_threadcount += 1End SyncLockEnd SubPublic Shared Sub Decrement()SyncLock (m_lock)m_threadcount -= 1End SyncLockEnd SubPublic Shared ReadOnly Property ThreadCount() As Int32GetDim _count As Int32SyncLock (m_lock)_count = m_threadcountEnd SyncLockReturn _countEnd GetEnd PropertyEnd ClassI use it by callingmythreadcount.incrementmythreadcount.decrementlabel1.text=mythreadcount.threadcountEverything works great but I''m wondering how it gets started. I meanhow is it loaded I guess. why doesn''t it need me to instigate it orwhatever. how does it know when to assign the variable m_threadcount to0 on the very first time a sub in the class is referenced? 解决方案Instance and Shared Variables: http://msdn.microsoft.com/library/en...fvbspec7_5.aspMythran 这篇关于试图理解课程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-25 23:19