internal bool StartOwningDisconnectHandling()
{
int oldValue;
SpinWait spin = new SpinWait();
while ((oldValue = Interlocked.CompareExchange(ref _ownershipState, 1, 0)) == 2)
{
// Must block until it equals 3 - we must be in the callback right now.
spin.SpinOnce();
}
Debug.Assert(oldValue != 1, "StartOwningDisconnectHandling called twice.");
return oldValue < 2;
}