Shortcut for Interlocked.Exchange in setting properties

I have the following simple part of a variable declaration: a class generated by a decompiler

Friend Class Project
    Private _Status As Integer
    Public Property Status As Integer
        Get
            Return Me._Status
        End Get
        Set(ByVal value As Integer)
            Interlocked.Exchange(Me._Status, value)
        End Set
    End Property
End Class

Is there any short form for this ad? In fact, it is used internally by the backgroundworker inside the class and accessed externally by other classes.

To understand the meaning of shorthand. Let me give you an example: The following gode is a shorthand

SyncLock lock
    z = 1
End SyncLock

for the next detailed code

Dim obj As Object = Me.lock
ObjectFlowControl.CheckForSyncLockOnValueType(obj)
Dim flag As Boolean = False
Try
    Monitor.Enter(obj, flag)
    Me.z = 1
Finally
    If (flag) Then
        Monitor.[Exit](obj)
    End If
End Try
+4
source share
2 answers

Interlocked.Exchange(Me._Status, value)

  • This is one liner, how much shorter do you think it can get?

  • Exchange (Int32) - , . , , SyncLock .

+3

, , Interlocked.Exchange, - . (Int32 .NET, .)

#, , volatile, .

private volatile int _Status;
public int Status
{
    get { return _Status; }
    set { _Status = value; }
}

, .

+3

Source: https://habr.com/ru/post/1658608/


All Articles