Advertisement
Guest User

SynchronousProgress_T

a guest
Mar 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1.         public class SynchronousProgress<T> : IProgress<T>
  2.         {
  3.             private readonly SynchronizationContext _Context;
  4.             private readonly Action<T> _Action;
  5.  
  6.             public SynchronousProgress(Action<T> action)
  7.             {
  8.                 _Action = action;
  9.                 _Context = SynchronizationContext.Current ?? new SynchronizationContext();
  10.             }
  11.  
  12.             private void Callback(object state)
  13.             {
  14.                 _Action?.Invoke((T)state);
  15.             }
  16.  
  17.             public void Report(T value)
  18.             {
  19.                 _Context.Send(Callback, value);
  20.             }
  21.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement