public void Dispose() { safeFileHandle?.Dispose(); fileStream?.Dispose(); StandardOutput?.Dispose(); FreeConsole(); }
public void Close() { if (_IsClosing) { return; } _IsClosing = true; try { foreach (var usbInterface in _UsbInterfaces) { usbInterface.Dispose(); } _UsbInterfaces.Clear(); _DeviceHandle?.Dispose(); _DeviceHandle = null; } catch (Exception) { //TODO: Logging } _IsClosing = false; }
public override void Close() { _DeviceHandle?.Dispose(); _DeviceHandle = null; base.Close(); }
public void Dispose() { if (_disposed) { return; } _disposed = true; GC.SuppressFinalize(this); _options.IoMetrics.FileClosed(_filename); _readHandle?.Dispose(); _readHandle = null; _handle?.Dispose(); _handle = null; if (_nativeOverlapped != null) { NativeMemory.Free((byte *)_nativeOverlapped, sizeof(NativeOverlapped)); _nativeOverlapped = null; } if (DeleteOnClose) { try { File.Delete(_filename); } catch (Exception) { // if we can't delete, nothing that we can do here. } } }
public void Dispose() { Disposed = true; GC.SuppressFinalize(this); _readHandle?.Dispose(); _handle.Dispose(); if (_nativeOverlapped != null) { Marshal.FreeHGlobal((IntPtr)_nativeOverlapped); _nativeOverlapped = null; } if (_segments != null) { Marshal.FreeHGlobal((IntPtr)_segments); _segments = null; } if (DeleteOnClose) { try { File.Delete(_filename); } catch (Exception) { // if we can't delete, nothing that we can do here. } } }
void Dispose(bool disposing) { if (disposing) { ReadSide?.Dispose(); WriteSide?.Dispose(); } }
public Win32FileJournalWriter(StorageEnvironmentOptions options, VoronPathSetting filename, long journalSize, Win32NativeFileAccess access = Win32NativeFileAccess.GenericWrite, Win32NativeFileShare shareMode = Win32NativeFileShare.Read) { try { _options = options; _filename = filename; _handle = Win32NativeFileMethods.CreateFile(filename.FullPath, access, shareMode, IntPtr.Zero, Win32NativeFileCreationDisposition.OpenAlways, options.WinOpenFlags, IntPtr.Zero); if (_handle.IsInvalid) { throw new IOException("When opening file " + filename, new Win32Exception(Marshal.GetLastWin32Error())); } var length = new FileInfo(filename.FullPath).Length; if (length < journalSize) { try { Win32NativeFileMethods.SetFileLength(_handle, journalSize); } catch (Exception) { try { _handle?.Dispose(); _handle = null; File.Delete(_filename.FullPath); } catch (Exception) { // there's nothing we can do about it } throw; } length = journalSize; } NumberOfAllocated4Kb = (int)(length / (4 * Constants.Size.Kilobyte)); _nativeOverlapped = (NativeOverlapped *)NativeMemory.AllocateMemory(sizeof(NativeOverlapped)); _nativeOverlapped->InternalLow = IntPtr.Zero; _nativeOverlapped->InternalHigh = IntPtr.Zero; } catch { Dispose(); throw; } }
protected override void DisposeInternal() { _fileStream?.Dispose(); _handle?.Dispose(); if (DeleteOnClose) { _fileInfo?.Delete(); } }
private void Dispose(bool disposing) { if (disposing) { channel?.Dispose(); fs?.Close(); fs?.Dispose(); } }
public void Dispose() { if (!_isDisposed) { _isDisposed = true; _readHandle?.Dispose(); _writeHandle?.Dispose(); ClosePseudoConsole(_ptyHandle); } }
protected virtual void Dispose(bool disposing) { if (_disposed) return; // Dispose of managed resources here. if (disposing) _safeFileHandle?.Dispose(); // Dispose of any unmanaged resources not wrapped in safe handles. _disposed = true; }
public void Dispose() { handle?.Dispose(); afsluiten?.Dispose(); reboot?.Dispose(); taskmananger?.Dispose(); vergrendel?.Dispose(); kladblok?.Dispose(); cpuCounter?.Dispose(); ramCounter.Dispose(); }
public void Close() { foreach (var usbInterface in UsbInterfaces) { usbInterface.Dispose(); } UsbInterfaces.Clear(); _DeviceHandle?.Dispose(); _DeviceHandle = null; }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { _safeHandle?.Dispose(); } _disposed = true; }
public override void Dispose() { IsInitialized = false; foreach (var usbInterface in _UsbInterfaces) { usbInterface.Dispose(); } _UsbInterfaces.Clear(); _DeviceHandle?.Dispose(); base.Dispose(); }
private static void InternalCreatePipe( out SafeFileHandle parentHandle, out SafeFileHandle childHandle, bool parentInputs) { var securityAttributesParent = new Interop.SecurityAttributes(); securityAttributesParent.bInheritHandle = Interop.BOOL.TRUE; SafeFileHandle hTmp = null; try { if (parentInputs) { CreatePipeWithSecurityAttributes( out childHandle, out hTmp, ref securityAttributesParent, 0); } else { CreatePipeWithSecurityAttributes( out hTmp, out childHandle, ref securityAttributesParent, 0); } // Duplicate the parent handle to be non-inheritable so that the child process // doesn't have access. This is done for correctness sake, exact reason is unclear. // One potential theory is that child process can do something brain dead like // closing the parent end of the pipe and there by getting into a blocking situation // as parent will not be draining the pipe at the other end anymore. SafeProcessHandle currentProcHandle = Kernel32.GetCurrentProcess(); if (!Kernel32.DuplicateHandle( currentProcHandle, hTmp, currentProcHandle, out parentHandle, 0, false, HandleOptions.DuplicateSameAccess)) { throw new Win32Exception(); } } finally { if (hTmp != null && !hTmp.IsInvalid) { hTmp.Dispose(); } } }
// Take reference, so we may easily add multiple interface support in the future internal void ReturnHandle(SafeWinUsbInterfaceHandle handle) { if (activeWinUsbHandle != handle) { throw new InvalidOperationException("Returning handle is not equal to active handle"); } if (Interlocked.Decrement(ref referenceCount) == 0) { activeWinUsbHandle.Dispose(); activeFileHandle.Dispose(); activeWinUsbHandle = null; activeFileHandle = null; } }
public bool Open() { device = new SafeFileHandle(NativeMethods.CreateFile(@"\\.\" + id, FileAccess.GENERIC_READ | FileAccess.GENERIC_WRITE, 0, IntPtr.Zero, CreationDisposition.OPEN_EXISTING, FileAttributes.FILE_ATTRIBUTE_NORMAL, IntPtr.Zero), true); if (device.IsInvalid) { device.Close(); device.Dispose(); device = null; } return(device != null); }
public override void Dispose() { if (Disposed) { return; } base.Dispose(); _fileStream?.Dispose(); _handle?.Dispose(); if (DeleteOnClose) { _fileInfo?.Delete(); } }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { handle.Dispose(); pin = null; console = null; excludeList = null; } disposed = true; }
public override void Dispose() { if (disposed) { return; } disposed = true; if (_ReadSafeFileHandle != null) { _ReadSafeFileHandle.Dispose(); _ReadSafeFileHandle = new SafeFileHandle((IntPtr)0, true); } base.Dispose(); }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { // get rid of managed resources } // get rid of unmanaged resources _driverHandle.Dispose(); implementation = new Lazy <KeyboardEmulatorAPI>(() => CreateInstance(), System.Threading.LazyThreadSafetyMode.PublicationOnly); disposed = true; }
/// <summary> /// Closes the serial port. /// </summary> /// <exception cref="System.ObjectDisposedException"/> /// <remarks> /// Closing the serial port invalidates actions that can be done to the serial port, /// but it does not prevent the serial port from being reopened /// </remarks> public void Close() { if (m_IsDisposed) { throw new ObjectDisposedException("WinNativeSerial"); } if (IsOpen) { m_CommOverlappedIo.Dispose(); m_CommOverlappedIo = null; m_CommState = null; m_CommModemStatus = null; m_ComPortHandle.Dispose(); m_ComPortHandle = null; } }
// Disposeパターン protected virtual void Dispose(bool disposing) { if (disposed) { return; // Dispose has already been called. } if (disposing) { handle.Dispose(); // マネージリソースの解放 // ToDo } // アンマネージリソースの解放 // ToDo disposed = true; }
/// <summary> /// Closes the Wirekite devices. /// </summary> /// <remarks> /// A closed device can no longer be used. It must be disconnected and connected again, /// or the Wirekite service must be restarted. /// </remarks> public void Close() { if (_deviceState == DeviceState.Closed) { return; } _ports.Clear(); _throttler.Clear(); _pendingRequests.Clear(); _service.RemoveDevice(this); WinUsb_Free(_interfaceHandle); _interfaceHandle = IntPtr.Zero; _deviceHandle.Dispose(); _deviceHandle = null; _deviceState = DeviceState.Closed; }
public void Dispose() { if (driveHandle != null) { if (driveStream != null) { driveStream.Close(); driveStream.Dispose(); } if (!driveHandle.IsClosed) { driveHandle.Close(); } driveHandle.Dispose(); driveHandle = null; } }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { handle.Dispose(); _host = null; console = null; client = null; TunnelDestroyed = true; } disposed = true; }
// Returns the std* handle of the current process that can be inherited by a child process. private static SafeFileHandle GetStdHandleForChild(int kind) { var handle = new SafeFileHandle(Kernel32.GetStdHandle(kind), false); // If we do not have a console window, we attach a new console to a child process. // In this case console pseudo handles cannot be inherited by a child process. // Ignore console pseudo handles and redirect from/to NUL instead, so that // our child processes should not stuck reading from an invisible console. if (handle.IsInvalid || (IsConsoleHandle(handle) && !HasConsoleWindow())) { handle.Dispose(); return(null); } return(handle); }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } // Dispose of managed resources here. if (disposing) { safeHandle.Dispose(); } // Dispose of any unmanaged resources not wrapped in safe handles. disposed = true; }
/// <summary> /// Closes the <see cref="UsbDevice"/> and disposes any <see cref="UsbDevice.ActiveEndpoints"/>. /// </summary> /// <returns>True on success.</returns> public override bool Close() { if (IsOpen) { ActiveEndpoints.Clear(); mUsbHandle.Dispose(); if (mSafeDevHandle != null) { if (!mSafeDevHandle.IsClosed) { mSafeDevHandle.Dispose(); } } } return(true); }
public static int test_0_sf_dispose () { SafeFileHandle sf = new SafeFileHandle ((IntPtr) 0x0d00d, false); sf.Dispose (); try { mono_xr (sf); } catch (ObjectDisposedException){ return 0; } return 1; }