public static async Task <TResult> UsingAsync <TResult>(this IBusyState state, Func <Task <TResult> > execute)
 {
     using (state.Begin())
     {
         return(await execute().ConfigureAwait(true));
     }
 }
 public static void Using(this IBusyState state, Action execute)
 {
     using (state.Begin())
     {
         execute();
     }
 }
 public static async Task UsingAsync(this IBusyState state, Func <Task> execute)
 {
     using (state.Begin())
     {
         await execute().ConfigureAwait(true);
     }
 }
 public static TResult Using <TResult>(this IBusyState state, Func <TResult> execute)
 {
     using (state.Begin())
     {
         return(execute());
     }
 }
示例#5
0
        public static void AllowCancel(this IBusyState busyState, CancellationTokenSource cancellationTokenSource, string cancelCaption)
        {
            busyState.AssertNotNull(nameof(busyState));
            cancellationTokenSource.AssertNotNull(nameof(cancellationTokenSource));

            busyState.CancellationCallback = () => cancellationTokenSource.Cancel();
            busyState.CancelCaption        = cancelCaption;
            busyState.CanCancel            = true;
        }
        private async Task PayloadBackgroundOperation(IBusyState state)
        {
            state.Description = "Direct payload progress";
            await Task.Run(() =>
            {
                for (var i = 0; i < 5; i++)
                {
                    Thread.Sleep(1000);
                    state.Description = $"Operation progress {i + 1} seconds passed";
                }
            });

            state.Description = "Direct payload progress ends";
        }
示例#7
0
 public BusyStateController(IBusyState state)
 {
     this.state   = state;
     state.IsBusy = true;
 }
 public BusyStateScope(IBusyState state)
 {
     state.Require();
     this.state = state;
 }
 public static IDisposable Begin(this IBusyState state) => new BusyStateScope(state);
示例#10
0
            public BusyScope(IBusyState busyState)
            {
                busyState.AssertNotNull(nameof(busyState));

                BusyState = busyState;
            }