public static bool Wait(string name, long timeout, bool relative) { using (var npfsHandle = new FileHandle( Win32.NamedPipePath + "\\", FileShareMode.ReadWrite, FileCreateOptions.SynchronousIoNonAlert, FileAccess.ReadAttributes | (FileAccess)StandardRights.Synchronize )) { using (var data = new MemoryAlloc(FilePipeWaitForBuffer.NameOffset + name.Length * 2)) { FilePipeWaitForBuffer info = new FilePipeWaitForBuffer(); info.Timeout = timeout; info.TimeoutSpecified = true; info.NameLength = name.Length * 2; data.WriteStruct <FilePipeWaitForBuffer>(info); data.WriteUnicodeString(FilePipeWaitForBuffer.NameOffset, name); NtStatus status; int returnLength; status = npfsHandle.FsControl(FsCtlWait, data, data.Size, IntPtr.Zero, 0, out returnLength); if (status == NtStatus.IoTimeout) { return(false); } if (status >= NtStatus.Error) { Win32.Throw(status); } return(true); } } }
public static bool Wait(string name, long timeout, bool relative) { using (var npfsHandle = new FileHandle( Win32.NamedPipePath + "\\", FileShareMode.ReadWrite, FileCreateOptions.SynchronousIoNonAlert, FileAccess.ReadAttributes | (FileAccess)StandardRights.Synchronize )) { using (var data = new MemoryAlloc(FilePipeWaitForBuffer.NameOffset + name.Length * 2)) { FilePipeWaitForBuffer info = new FilePipeWaitForBuffer(); info.Timeout = timeout; info.TimeoutSpecified = true; info.NameLength = name.Length * 2; data.WriteStruct<FilePipeWaitForBuffer>(info); data.WriteUnicodeString(FilePipeWaitForBuffer.NameOffset, name); NtStatus status; int returnLength; status = npfsHandle.FsControl(FsCtlWait, data, data.Size, IntPtr.Zero, 0, out returnLength); if (status == NtStatus.IoTimeout) return false; if (status >= NtStatus.Error) Win32.ThrowLastError(status); return true; } } }