Exemplo n.º 1
0
 public static async Task <TResult> UsingAsync <TResult>(this IBusyState state, Func <Task <TResult> > execute)
 {
     using (state.Begin())
     {
         return(await execute().ConfigureAwait(true));
     }
 }
Exemplo n.º 2
0
 public static void Using(this IBusyState state, Action execute)
 {
     using (state.Begin())
     {
         execute();
     }
 }
Exemplo n.º 3
0
 public static async Task UsingAsync(this IBusyState state, Func <Task> execute)
 {
     using (state.Begin())
     {
         await execute().ConfigureAwait(true);
     }
 }
Exemplo n.º 4
0
 public static TResult Using <TResult>(this IBusyState state, Func <TResult> execute)
 {
     using (state.Begin())
     {
         return(execute());
     }
 }
Exemplo n.º 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";
        }
Exemplo n.º 7
0
 public BusyStateController(IBusyState state)
 {
     this.state   = state;
     state.IsBusy = true;
 }
Exemplo n.º 8
0
 public BusyStateScope(IBusyState state)
 {
     state.Require();
     this.state = state;
 }
Exemplo n.º 9
0
 public static IDisposable Begin(this IBusyState state) => new BusyStateScope(state);
Exemplo n.º 10
0
            public BusyScope(IBusyState busyState)
            {
                busyState.AssertNotNull(nameof(busyState));

                BusyState = busyState;
            }