本文介绍了返回是否锁内有什么差别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Public _objLock As Object = New Object
Public ReadOnly Property MyObjects() As IEnumerable(Of Object)
    Get
        SyncLock _objLock
            If _myObjects Is Nothing Then
                _myObject = LoadMyObjects()
            End If
            Return _myObjects
        End SyncLock
    End Get
End Property

的样品有两条

Public _objLock As Object = New Object
Public ReadOnly Property MyObjects() As IEnumerable(Of Object)
    Get
        SyncLock _objLock
            If _myObjects Is Nothing Then
                _myObject = LoadMyObjects()
            End If              
        End SyncLock
        Return _myObjects
    End Get
End Property

会不会有这些实现之间有什么区别?

Will there be any difference between these implementations ?

推荐答案

没有,返回一个锁里面没有什么区别。一旦你离开了锁,这将不复存在。

No, returning inside a lock makes no difference. Once you leave the lock, it will cease to exist.

这篇关于返回是否锁内有什么差别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 05:18