Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle.Dispose C# (CSharp) Méthode

Dispose() protected méthode

protected Dispose ( bool disposing ) : void
disposing bool
Résultat void
        protected override void Dispose(bool disposing)
        {
            if (disposing && _ownsFileStream)
            {
                // Clean up the file descriptor (either for a file on disk or a shared memory object) if we created it
                _fileStream.Dispose();
            }
            base.Dispose(disposing);
        }

Usage Example

Exemple #1
0
        private static Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle CreateCore(SafeFileHandle fileHandle, string mapName, HandleInheritability inheritability, MemoryMappedFileSecurity memoryMappedFileSecurity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, long capacity)
        {
            Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle handle = null;
            object obj2;

            Microsoft.Win32.UnsafeNativeMethods.SECURITY_ATTRIBUTES lpAttributes = GetSecAttrs(inheritability, memoryMappedFileSecurity, out obj2);
            int dwMaximumSizeLow  = (int)(((ulong)capacity) & 0xffffffffL);
            int dwMaximumSizeHigh = (int)(capacity >> 0x20);

            try
            {
                handle = Microsoft.Win32.UnsafeNativeMethods.CreateFileMapping(fileHandle, lpAttributes, GetPageAccess(access) | options, dwMaximumSizeHigh, dwMaximumSizeLow, mapName);
                int errorCode = Marshal.GetLastWin32Error();
                if (!handle.IsInvalid && (errorCode == 0xb7))
                {
                    handle.Dispose();
                    System.IO.__Error.WinIOError(errorCode, string.Empty);
                    return(handle);
                }
                if (handle.IsInvalid)
                {
                    System.IO.__Error.WinIOError(errorCode, string.Empty);
                }
            }
            finally
            {
                if (obj2 != null)
                {
                    ((GCHandle)obj2).Free();
                }
            }
            return(handle);
        }