/// <summary> /// Reduces the size of the virtual hard disk (VHD) backing store file. Supports both sync and async modes. /// </summary> /// <param name="overlapped">If not null, the operation runs in async mode</param> /// <param name="flags">Flags for Compact operation</param> public void Compact( IntPtr overlapped, COMPACT_VIRTUAL_DISK_FLAG flags = COMPACT_VIRTUAL_DISK_FLAG.COMPACT_VIRTUAL_DISK_FLAG_NONE) { var compactParams = new NativeMethods.COMPACT_VIRTUAL_DISK_PARAMETERS(); compactParams.Version = NativeMethods.COMPACT_VIRTUAL_DISK_VERSION.COMPACT_VIRTUAL_DISK_VERSION_1; var ret = NativeMethods.CompactVirtualDisk(CheckDisposed(), flags, ref compactParams, overlapped); if ((overlapped == IntPtr.Zero && ret != NativeMethods.ERROR_SUCCESS) || (overlapped != IntPtr.Zero && ret != NativeMethods.ERROR_IO_PENDING)) { throw new Win32Exception(ret); } }
/// <summary> /// Reduces the size of the virtual hard disk (VHD) backing store file. /// </summary> /// <param name="flags">Flags for Compact operation</param> public void Compact(COMPACT_VIRTUAL_DISK_FLAG flags = COMPACT_VIRTUAL_DISK_FLAG.COMPACT_VIRTUAL_DISK_FLAG_NONE) => Compact(IntPtr.Zero, flags);
public static extern int CompactVirtualDisk(IntPtr VirtualDiskHandle, COMPACT_VIRTUAL_DISK_FLAG Flags, ref COMPACT_VIRTUAL_DISK_PARAMETERS Parameters, IntPtr Overlapped);
public static extern Int32 CompactVirtualDisk(VirtualDiskSafeHandle VirtualDiskHandle, COMPACT_VIRTUAL_DISK_FLAG Flags, ref COMPACT_VIRTUAL_DISK_PARAMETERS Parameters, IntPtr Overlapped);
public static extern UInt32 CompactVirtualDisk( VirtualDiskSafeHandle VirtualDiskHandle, COMPACT_VIRTUAL_DISK_FLAG Flags, IntPtr Parameters, // to make it optional (pass IntPtr.Zero) IntPtr Overlapped); // to make it optional (pass IntPtr.Zero)
public static extern UInt32 CompactVirtualDisk( VirtualDiskSafeHandle VirtualDiskHandle, COMPACT_VIRTUAL_DISK_FLAG Flags, ref COMPACT_VIRTUAL_DISK_PARAMETERS Parameters, ref OVERLAPPED Overlapped);