G
Guest
In C#, how do I replace using VB local static variable declarations to handle
method reentrancy. Note, if you use a class-scope variable instead of a local
one, then you run the risk of inadvertently changing the variable's value in
another method that is performing the same technique.
The Interlocked.Exchange class uses a class-scope class attribute.
Reentrancy is not just a problem for user events (e.g., overzealous users
double-clicking on a button). Reentrancy is also a problem in systems that
use concurrency, where methods may be overstacked in the call-stack.
VB example:
Private Function foo()
Static st_blnInHere As Boolean
Try
'$ To avoid reentrancy:
If st_blnInHere Then
Exit Try
Else
st_blnInHere = True
End If
'$ critical code here...
st_blnInHere = False
Catch ex As Exception
st_blnInHere = False
Finally
End Try
End Function
method reentrancy. Note, if you use a class-scope variable instead of a local
one, then you run the risk of inadvertently changing the variable's value in
another method that is performing the same technique.
The Interlocked.Exchange class uses a class-scope class attribute.
Reentrancy is not just a problem for user events (e.g., overzealous users
double-clicking on a button). Reentrancy is also a problem in systems that
use concurrency, where methods may be overstacked in the call-stack.
VB example:
Private Function foo()
Static st_blnInHere As Boolean
Try
'$ To avoid reentrancy:
If st_blnInHere Then
Exit Try
Else
st_blnInHere = True
End If
'$ critical code here...
st_blnInHere = False
Catch ex As Exception
st_blnInHere = False
Finally
End Try
End Function