//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public boolean waitFor(long timeout, java.util.concurrent.TimeUnit unit) throws InterruptedException public override bool WaitFor(long timeout, TimeUnit unit) { if (getExitCodeProcess(Handle) != STILL_ACTIVE) { return(true); } if (timeout <= 0) { return(false); } long remainingNanos = unit.ToNanos(timeout); long deadline = System.nanoTime() + remainingNanos; do { // Round up to next millisecond long msTimeout = TimeUnit.NANOSECONDS.ToMillis(remainingNanos + 999_999L); waitForTimeoutInterruptibly(Handle, msTimeout); if (Thread.Interrupted()) { throw new InterruptedException(); } if (getExitCodeProcess(Handle) != STILL_ACTIVE) { return(true); } remainingNanos = deadline - System.nanoTime(); } while (remainingNanos > 0); return(getExitCodeProcess(Handle) != STILL_ACTIVE); }
/// <summary> /// Causes the current thread to wait, if necessary, until the /// subprocess represented by this {@code Process} object has /// terminated, or the specified waiting time elapses. /// /// <para>If the subprocess has already terminated then this method returns /// immediately with the value {@code true}. If the process has not /// terminated and the timeout value is less than, or equal to, zero, then /// this method returns immediately with the value {@code false}. /// /// </para> /// <para>The default implementation of this methods polls the {@code exitValue} /// to check if the process has terminated. Concrete implementations of this /// class are strongly encouraged to override this method with a more /// efficient implementation. /// /// </para> /// </summary> /// <param name="timeout"> the maximum time to wait </param> /// <param name="unit"> the time unit of the {@code timeout} argument </param> /// <returns> {@code true} if the subprocess has exited and {@code false} if /// the waiting time elapsed before the subprocess has exited. </returns> /// <exception cref="InterruptedException"> if the current thread is interrupted /// while waiting. </exception> /// <exception cref="NullPointerException"> if unit is null /// @since 1.8 </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public boolean waitFor(long timeout, java.util.concurrent.TimeUnit unit) throws InterruptedException public virtual bool WaitFor(long timeout, TimeUnit unit) { long startTime = System.nanoTime(); long rem = unit.ToNanos(timeout); do { try { ExitValue(); return(true); } catch (IllegalThreadStateException) { if (rem > 0) { Thread.Sleep(System.Math.Min(TimeUnit.NANOSECONDS.ToMillis(rem) + 1, 100)); } } rem = unit.ToNanos(timeout) - (System.nanoTime() - startTime); } while (rem > 0); return(false); }