mscorlib(4.0.0.0) API with additions
Progress.cs
1 using System.Threading;
2 
3 namespace System
4 {
7  [__DynamicallyInvokable]
8  public class Progress<T> : IProgress<T>
9  {
10  private readonly SynchronizationContext m_synchronizationContext;
11 
12  private readonly Action<T> m_handler;
13 
14  private readonly SendOrPostCallback m_invokeHandlers;
15 
17  [__DynamicallyInvokable]
18  [method: __DynamicallyInvokable]
19  public event EventHandler<T> ProgressChanged;
20 
22  [__DynamicallyInvokable]
23  public Progress()
24  {
25  m_synchronizationContext = (SynchronizationContext.CurrentNoFlow ?? ProgressStatics.DefaultContext);
26  m_invokeHandlers = InvokeHandlers;
27  }
28 
31  [__DynamicallyInvokable]
32  public Progress(Action<T> handler)
33  : this()
34  {
35  if (handler == null)
36  {
37  throw new ArgumentNullException("handler");
38  }
39  m_handler = handler;
40  }
41 
44  [__DynamicallyInvokable]
45  protected virtual void OnReport(T value)
46  {
47  Action<T> handler = m_handler;
48  EventHandler<T> progressChanged = this.ProgressChanged;
49  if (handler != null || progressChanged != null)
50  {
51  m_synchronizationContext.Post(m_invokeHandlers, value);
52  }
53  }
54 
57  [__DynamicallyInvokable]
58  void IProgress<T>.Report(T value)
59  {
60  OnReport(value);
61  }
62 
63  private void InvokeHandlers(object state)
64  {
65  T val = (T)state;
66  Action<T> handler = m_handler;
67  EventHandler<T> progressChanged = this.ProgressChanged;
68  handler?.Invoke(val);
69  progressChanged?.Invoke(this, val);
70  }
71  }
72 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
void Report(T value)
Reports a progress update.
delegate void SendOrPostCallback(object state)
Represents a method to be called when a message is to be dispatched to a synchronization context.
Definition: __Canon.cs:3
virtual void OnReport(T value)
Reports a progress change.
Definition: Progress.cs:45
Defines a provider for progress updates.
Definition: IProgress.cs:6
EventHandler< T > ProgressChanged
Raised for each reported progress value.
Definition: Progress.cs:19
Progress()
Initializes the T:System.Progress`1 object.
Definition: Progress.cs:23
Provides the basic functionality for propagating a synchronization context in various synchronization...
Progress(Action< T > handler)
Initializes the T:System.Progress`1 object with the specified callback.
Definition: Progress.cs:32
Provides an T:System.IProgress`1 that invokes callbacks for each reported progress value.
Definition: Progress.cs:8