コード例 #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)));
 }
コード例 #3
0
 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));
 }
コード例 #5
0
 public static IAsyncAction Wrap <TProgress>(IAsyncActionWithProgress <TProgress> action)
 => Wrap(action, 250);
コード例 #6
0
 /// <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);
コード例 #11
0
 private static void TranscodeProgress(IAsyncActionWithProgress <double> asyncinfo, double progressinfo)
 {
 }
コード例 #12
0
ファイル: util.cs プロジェクト: helmuttheis/hmsspx
 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));
 }
コード例 #17
0
        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();
 }
コード例 #19
0
        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);
コード例 #22
0
 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);
コード例 #24
0
 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);
 }
コード例 #29
0
        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);
 }
コード例 #31
0
        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);