Exemple #1
0
        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);
            }
        }
Exemple #2
0
 /// <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);
     }
 }
Exemple #3
0
        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);
        }
Exemple #4
0
 /// <summary>
 /// Aborts an ongoing copy operation.
 /// </summary>
 public void Abort()
 {
     this.cancelRequested = true;
     AsyncStreamCopier <T> .ForceAbort(this, false);
 }