Пример #1
0
        private void SocketElevate()
        {
            if (!IsConnected)
            {
                return;
            }

            _elevateMutex.Reset();

            if (_socketReader != null)
            {
                _socketReader.Cancel();
            }

            // Wait for other reads to finish
            if (_socketWriter != null && _socketWriter.Status == AsyncStatus.Started)
            {
                try
                {
                    _socketWriter.AsTask().Wait(4000);
                }
                catch
                {
                    if (_socketWriter.Status == AsyncStatus.Started)
                    {
                        ConnectionError(ErrorType.WriteStateMismatch, ErrorPolicyType.Reconnect);
                        return;
                    }
                }
            }

            _socketElevator           = _socket.UpgradeToSslAsync(SocketProtectionLevel.SslAllowNullEncryption, _hostname);
            _socketElevator.Completed = OnSocketElevatorCompleted;
        }
Пример #2
0
        private void CleanupState()
        {
            IsConnected = false;

            _manager.ProcessComplete.Set();

            _elevateMutex.Set();

            _manager.Parser.Clear();

            if (_socketConnector != null)
            {
                _socketConnector.Cancel();
            }
            if (_socketElevator != null)
            {
                _socketElevator.Cancel();
            }
            if (_socketReader != null)
            {
                _socketReader.Cancel();
            }
            if (_socketWriter != null)
            {
                _socketWriter.Cancel();
            }

            _socket.Dispose();
        }
 private void ResetRequest()
 {
     if (sendRequestOperation != null)
     {
         sendRequestOperation.Cancel();
         sendRequestOperation = null;
     }
     if (readAsInputStreamOperation != null)
     {
         readAsInputStreamOperation.Cancel();
         readAsInputStreamOperation = null;
     }
     if (readOperation != null)
     {
         readOperation.Cancel();
         readOperation = null;
     }
     if (inputStream != null)
     {
         inputStream.Dispose();
         inputStream = null;
     }
     if (httpRequest != null)
     {
         httpRequest.Dispose();
         httpRequest = null;
     }
 }
Пример #4
0
 public void CancelUpload()
 {
     if (UploadOperation.Status == AsyncStatus.Started)
     {
         UploadOperation.Cancel();
     }
 }
Пример #5
0
 /// <summary>
 /// Cancel the transcode
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnCancel(object sender, RoutedEventArgs e)
 {
     if (_operation != null && _operation.Status == AsyncStatus.Started)
     {
         CancelButton.IsEnabled = false;
         _operation.Cancel();
     }
 }
Пример #6
0
 public void CancelDownload()
 {
     if (Finished)
     {
         return;
     }
     DownloadOperation.Cancel();
 }
 public override void Dispose()
 {
     if (_status == BackgroundDownloadStatus.Downloading)
     {
         _cancelSource.Cancel();
         if (_downloadOperation != null)
         {
             _downloadOperation.Cancel();
         }
     }
     base.Dispose();
 }
 private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     args.Cancel = true;
     if (PrimaryButtonText == "开始")
     {
         Start();
     }
     else
     {
         operationWithProgress.Cancel();
         PrimaryButtonText = "开始";
     }
 }
Пример #9
0
        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Stop any in-process transfer
                _transferOperation.Cancel();

                Cancel.IsEnabled = false;
            }
            catch
            {
                // don't bomb out on a cancel op
                Analytics.LogEvent(AnalyticsEvent.TransferCancelError);
            }
        }
Пример #10
0
        public static R WaitResult <R, P>(this IAsyncOperationWithProgress <R, P> token, int t) where R : class
        {
            Task.Run(async() => {
                await Task.Delay(t);
                if (token.Status == AsyncStatus.Completed)
                {
                    return;
                }
                token.Cancel();
            });

            return(Task.Run(async() => {
                var c = await token;
                return c;
            }).GetAwaiter().GetResult());
            //  token.AsTask().GetAwaiter().GetResult()  ;//.AsTask().GetAwaiter();
        }
Пример #11
0
 private void CancelButton_Click(object sender, RoutedEventArgs e)
 {
     _renderTask?.Cancel();
 }