private static void ForceAbort(AsyncStreamCopier <T> copier, bool timedOut) { ExecutionState <T> state = copier.state; if (state != null) { if (state.Req != null) { try { state.ReqTimedOut = timedOut; #if WINDOWS_DESKTOP && !WINDOWS_PHONE state.Req.Abort(); #endif } catch (Exception) { // no op } } copier.exceptionRef = timedOut ? Exceptions.GenerateTimeoutException(state.Cmd != null ? state.Cmd.CurrentResult : null, null) : Exceptions.GenerateCancellationException(state.Cmd != null ? state.Cmd.CurrentResult : null, null); } }
/// <summary> /// Callback for timeout timer. Aborts the AsyncStreamCopier operation if a timeout occurs. /// </summary> /// <param name="copier">AsyncStreamCopier operation.</param> /// <param name="timedOut">True if the timer has timed out, false otherwise.</param> private static void MaximumCopyTimeCallback(object copier, bool timedOut) { if (timedOut) { AsyncStreamCopier <T> asyncCopier = (AsyncStreamCopier <T>)copier; AsyncStreamCopier <T> .ForceAbort(asyncCopier, true); } }
internal static void WriteToAsync <T>(this Stream stream, Stream toStream, long?copyLength, long?maxLength, bool calculateMd5, ExecutionState <T> executionState, StreamDescriptor streamCopyState, Action <ExecutionState <T> > completed) { AsyncStreamCopier <T> copier = new AsyncStreamCopier <T>(stream, toStream, executionState, GetBufferSize(stream), calculateMd5, streamCopyState); copier.StartCopyStream(completed, copyLength, maxLength); }
/// <summary> /// Aborts an ongoing copy operation. /// </summary> public void Abort() { this.cancelRequested = true; AsyncStreamCopier <T> .ForceAbort(this, false); }