System.IO.FileStream.CompareExchangeCurrentOverlappedOwner C# (CSharp) Method

CompareExchangeCurrentOverlappedOwner() private method

private CompareExchangeCurrentOverlappedOwner ( FileStreamCompletionSource newSource, FileStreamCompletionSource existingSource ) : FileStreamCompletionSource
newSource FileStreamCompletionSource
existingSource FileStreamCompletionSource
return FileStreamCompletionSource
        private FileStreamCompletionSource CompareExchangeCurrentOverlappedOwner(FileStreamCompletionSource newSource, FileStreamCompletionSource existingSource) => Interlocked.CompareExchange(ref _currentOverlappedOwner, newSource, existingSource);

Usage Example

            internal virtual void ReleaseNativeResource()
            {
                // Ensure that cancellation has been completed and cleaned up.
                _cancellationRegistration.Dispose();

                // Free the overlapped.
                // NOTE: The cancellation must *NOT* be running at this point, or it may observe freed memory
                // (this is why we disposed the registration above).
                if (_overlapped != null)
                {
                    _stream._fileHandle.ThreadPoolBinding !.FreeNativeOverlapped(_overlapped);
                    _overlapped = null;
                }

                // Ensure we're no longer set as the current completion source (we may not have been to begin with).
                // Only one operation at a time is eligible to use the preallocated overlapped,
                _stream.CompareExchangeCurrentOverlappedOwner(null, this);
            }
All Usage Examples Of System.IO.FileStream::CompareExchangeCurrentOverlappedOwner