示例#1
0
 private static void ConcatenateProgress <TProgress>(IAsyncActionWithProgress <TProgress> source, IProgress <TProgress> sink)
 {
     // This is separated out into a separate method so that we only pay the costs of compiler-generated closure if progress is non-null.
     source.Progress += new AsyncActionProgressHandler <TProgress>((_, info) => sink.Report(info));
 }
示例#2
0
 public static void TrackAsyncAction <TProgress>(IAsyncActionWithProgress <TProgress> action, Func <TProgress, double> progressConverter)
 {
     DisableView(null);
     action.Completed = (s, e) => Parent.Dispatcher.Begin(EnableView);
     action.Progress  = (s, p) => Parent.Dispatcher.Begin(() => DisableView(progressConverter(p)));
 }
 private void TranscodeComplete(IAsyncActionWithProgress <double> asyncInfo, AsyncStatus asyncStatus)
 {
     Debug.WriteLine("TranscodeComplete");
 }
示例#4
0
 /// <summary>Gets a Task to represent the asynchronous operation.</summary>
 /// <param name="source">The asynchronous operation.</param>
 /// <param name="progress">The progress object used to receive progress updates.</param>
 /// <returns>The Task representing the asynchronous operation.</returns>
 public static Task AsTask <TProgress>(this IAsyncActionWithProgress <TProgress> source, IProgress <TProgress> progress)
 {
     return(AsTask(source, CancellationToken.None, progress));
 }
 public static IAsyncAction Wrap <TProgress>(IAsyncActionWithProgress <TProgress> action)
 => Wrap(action, 250);
 /// <summary>Bridge to Completed handler on IAsyncActionWithProgress{TProgress}.</summary>
 internal void CompleteFromAsyncActionWithProgress(IAsyncActionWithProgress <TProgress> asyncInfo, AsyncStatus asyncStatus)
 {
     Complete(asyncInfo, null, asyncStatus);
 }
示例#7
0
 private void action_Progress(IAsyncActionWithProgress <TProgress> asyncInfo, TProgress progressInfo)
 => this.progress?.Invoke(this, progressInfo);
示例#8
0
 public static Task AsTask <TProgress>(this IAsyncActionWithProgress <TProgress> source)
 {
     throw new NotImplementedException();
 }
示例#9
0
 public MulticastAsyncAction(IAsyncActionWithProgress <TProgress> action) : base(action)
 {
     action.Completed = this.action_Completed;
     action.Progress  = this.action_Progress;
 }
示例#10
0
 private void action_Completed(IAsyncActionWithProgress <TProgress> sender, AsyncStatus e)
 => this.completed?.Invoke(this, e);
 private static void TranscodeProgress(IAsyncActionWithProgress <double> asyncinfo, double progressinfo)
 {
 }
示例#12
0
 public static TaskAwaiter GetAwaiter <TProgress>(this IAsyncActionWithProgress <Windows.Web.Http.HttpResponseMessage, TProgress> source)
 {
     return(WindowsRuntimeSystemExtensions.AsTask(source).GetAwaiter());
 }
示例#13
0
 public HRESULT Invoke([NativeTypeName("IAsyncActionWithProgress<TProgress_logical> *")] IAsyncActionWithProgress <TProgress> *asyncInfo, [NativeTypeName("TProgress_abi")] TProgress progressInfo)
 {
     return(((delegate * unmanaged <IAsyncActionProgressHandler <TProgress> *, IAsyncActionWithProgress <TProgress> *, TProgress, int>)(lpVtbl[3]))((IAsyncActionProgressHandler <TProgress> *)Unsafe.AsPointer(ref this), asyncInfo, progressInfo));
 }
示例#14
0
 public static TaskAwaiter GetAwaiter <TProgress>(this IAsyncActionWithProgress <TProgress> source)
 {
     return(AsTask(source).GetAwaiter());
 }
示例#15
0
 void TranscodeComplete(IAsyncActionWithProgress <double> asyncInfo, AsyncStatus status)
 {
     asyncInfo.GetResults();
 }
示例#16
0
 public HRESULT Invoke([NativeTypeName("IAsyncActionWithProgress<TProgress_logical> *")] IAsyncActionWithProgress <TProgress> *asyncInfo, [NativeTypeName("Windows::Foundation::AsyncStatus")] AsyncStatus status)
 {
     return(((delegate * unmanaged <IAsyncActionWithProgressCompletedHandler <TProgress> *, IAsyncActionWithProgress <TProgress> *, AsyncStatus, int>)(lpVtbl[3]))((IAsyncActionWithProgressCompletedHandler <TProgress> *)Unsafe.AsPointer(ref this), asyncInfo, status));
 }
        private void OnProgressChanged(IAsyncActionWithProgress<int> asyncInfo, int progress)
        {
            if (this.ViewModel.Status == AsyncStatus.Started)
                this.progressBar1.Visibility = Windows.UI.Xaml.Visibility.Visible;
            else
                this.progressBar1.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            if (progress > 30)
            {//可以读取首页
                this.DoDisplayDataAsync();
            }
        }
示例#18
0
 public static Task AsTask <TProgress>(this IAsyncActionWithProgress <TProgress> source, CancellationToken cancellationToken, IProgress <TProgress> progress)
 {
     throw new NotImplementedException();
 }
        private void OnCompleted(IAsyncActionWithProgress<int> progress, AsyncStatus status)
        {
            this.progressBar1.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            this.ViewModel.Progress -= new AsyncActionProgressHandler<int>(this.OnProgressChanged);
            this.ViewModel.Completed -= new AsyncActionWithProgressCompletedHandler<int>(this.OnCompleted);
        }
示例#20
0
 /*
  * Method for displaying the progress
  */
 private void TranscodeProgress(IAsyncActionWithProgress <double> asyncInfo, double percent)
 {
     // Display or handle progress info.
     System.Diagnostics.Debug.WriteLine(percent);
 }
示例#21
0
 public static Task AsTask <TProgress>(this IAsyncActionWithProgress <TProgress> source, IProgress <TProgress> progress)
 => source.AsTaskCore(CancellationToken.None, progress);
 private async void OnProgress(IAsyncActionWithProgress <double> asyncInfo, double progressInfo)
 {
     await
     ProgressBar.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                     delegate { ProgressBar.Value = progressInfo; });
 }
示例#23
0
 public static async Task AsTask <TProgress>(this IAsyncActionWithProgress <TProgress> source, CancellationToken cancellationToken, IProgress <TProgress> progress)
 => source.AsTaskCore(cancellationToken, progress);
 private void TranscodeProgress(IAsyncActionWithProgress <double> asyncInfo, double progressInfo)
 {
     Debug.WriteLine("TranscodeProgress");
 }
示例#25
0
 private static async Task AsTaskCore <TProgress>(this IAsyncActionWithProgress <TProgress> source, CancellationToken ct, IProgress <TProgress>?progress = null)
 {
     if (source is IAsyncActionWithProgressInternal <TProgress> operation)
     {
         using var _ = ct.CanBeCanceled ? ct.Register(operation.Cancel) : default;
         if (progress is {})
示例#26
0
        /// <summary>Gets a Task to represent the asynchronous operation.</summary>
        /// <param name="source">The asynchronous operation.</param>
        /// <param name="cancellationToken">The token used to request cancellation of the asynchronous operation.</param>
        /// <param name="progress">The progress object used to receive progress updates.</param>
        /// <returns>The Task representing the asynchronous operation.</returns>
        public static Task AsTask <TProgress>(this IAsyncActionWithProgress <TProgress> source,
                                              CancellationToken cancellationToken, IProgress <TProgress> progress)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            Contract.EndContractBlock();

            // If source is actually a NetFx-to-WinRT adapter, unwrap it instead of creating a new Task:
            var wrapper = source as TaskToAsyncActionWithProgressAdapter <TProgress>;

            if (wrapper != null && !wrapper.CompletedSynchronously)
            {
                Task innerTask = wrapper.Task;
                Debug.Assert(innerTask != null);
                Debug.Assert(innerTask.Status != TaskStatus.Created);  // Is WaitingForActivation a legal state at this moment?

                if (!innerTask.IsCompleted)
                {
                    // The race here is benign: If the task completes here, the concatinations are useless, but not damaging.

                    if (cancellationToken.CanBeCanceled && wrapper.CancelTokenSource != null)
                    {
                        ConcatenateCancelTokens(cancellationToken, wrapper.CancelTokenSource, innerTask);
                    }

                    if (progress != null)
                    {
                        ConcatenateProgress(source, progress);
                    }
                }

                return(innerTask);
            }

            // Fast path to return a completed Task if the operation has already completed:
            switch (source.Status)
            {
            case AsyncStatus.Completed:
                return(Task.CompletedTask);

            case AsyncStatus.Error:
                return(Task.FromException(source.ErrorCode.AttachRestrictedErrorInfo()));

            case AsyncStatus.Canceled:
                return(Task.FromCanceled(cancellationToken.IsCancellationRequested ? cancellationToken : new CancellationToken(true)));
            }

            // Benign race: source may complete here. Things still work, just not taking the fast path.

            // Forward progress reports:
            if (progress != null)
            {
                ConcatenateProgress(source, progress);
            }

            // Source is not a NetFx-to-WinRT adapter, but a native future. Hook up the task:
            var bridge = new AsyncInfoToTaskBridge <VoidValueTypeParameter>(cancellationToken);

            try
            {
                source.Completed = new AsyncActionWithProgressCompletedHandler <TProgress>(bridge.CompleteFromAsyncActionWithProgress);
                bridge.RegisterForCancellation(source);
            }
            catch
            {
                AsyncCausalitySupport.RemoveFromActiveTasks(bridge.Task);
            }
            return(bridge.Task);
        }
示例#27
0
 // <SnippetTranscodeCallbacks>
 void TranscodeProgress(IAsyncActionWithProgress <double> asyncInfo, double percent)
 {
     // Display or handle progress info.
 }
示例#28
0
 public static void TrackAsyncAction(IAsyncActionWithProgress <double> action)
 {
     TrackAsyncAction(action, p => p);
 }
        private void OnProgressChanged(IAsyncActionWithProgress<int> asyncInfo, int progress)
        {
            this.ProgressBar1.Value = progress;

            //if (this.AddFileViewModel.Status == AsyncStatus.Started)
            //{
            //    this.ProgressBar1.Value = progress;
            //}
            //else
            //{
            //    this.ProgressBar1.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            //    this.ProgressBar1.IsIndeterminate = false;
            //}
        }
示例#30
0
 public static void TrackAsyncAction(IAsyncActionWithProgress <double> action, AsyncActionWithProgressCompletedHandler <double> completed)
 {
     TrackAsyncAction(action, p => p, completed);
 }
        private async void OnCompleted(IAsyncActionWithProgress<int> progress, AsyncStatus status)
        {
            await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                new Windows.UI.Core.DispatchedHandler(() =>
                {
                    this.ProgressBar1.Value = 100;
                    this.ProgressBar1.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    this.ProgressBar1.IsIndeterminate = false;

                    this.AddFileViewModel.Progress -= new AsyncActionProgressHandler<int>(this.OnProgressChanged);
                    this.AddFileViewModel.Completed -= new AsyncActionWithProgressCompletedHandler<int>(this.OnCompleted);
                }));
        }
示例#32
0
 /// <summary>Gets a Task to represent the asynchronous operation.</summary>
 /// <param name="source">The asynchronous operation.</param>
 /// <param name="cancellationToken">The token used to request cancellation of the asynchronous operation.</param>
 /// <returns>The Task representing the asynchronous operation.</returns>
 public static Task AsTask <TProgress>(this IAsyncActionWithProgress <TProgress> source, CancellationToken cancellationToken)
 {
     return(AsTask(source, cancellationToken, null));
 }
示例#33
0
 public static IAsyncAction AsAsyncAction <TProgress>(this IAsyncActionWithProgress <TProgress> action)
 => AsAsyncAction(action, null);