public void InvokeProgressCallbacks() { if (_progressCallbacks != null) { foreach (var item in _progressCallbacks) { CallbackUtility.InvokeProgressCallback(_op, item.Callback, item.SyncContext); } } }
private void InvokeProgressCallback(object callback, SynchronizationContext syncContext) { if (syncContext == null || syncContext == SynchronizationContext.Current) { CallbackUtility.InvokeProgressCallback(this, callback); } else { syncContext.Post(args => CallbackUtility.InvokeProgressCallback(this, args), callback); } }
/// <summary> /// Adds a callback to be executed when the operation progress has changed. If the operation is completed <paramref name="action"/> is invoked /// on the <paramref name="syncContext"/> specified. /// </summary> /// <remarks> /// The <paramref name="action"/> is invoked on a <see cref="SynchronizationContext"/> specified. Throwing an exception from the callback might cause unspecified behaviour. /// </remarks> /// <param name="action">The callback to be executed when the operation progress has changed.</param> /// <param name="syncContext">If not <see langword="null"/> method attempts to marshal the continuation to the synchronization context. /// Otherwise the callback is invoked on a thread that initiated the operation. /// </param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="action"/> is <see langword="null"/>.</exception> /// <exception cref="ObjectDisposedException">Thrown is the operation has been disposed.</exception> /// <seealso cref="AddCompletionCallback(object, SynchronizationContext)"/> /// <seealso cref="RemoveCallback(object)"/> public void AddProgressCallback(object action, SynchronizationContext syncContext) { ThrowIfDisposed(); if (action == null) { throw new ArgumentNullException(nameof(action)); } if (!TryAddCallback(action, syncContext, false)) { CallbackUtility.InvokeProgressCallback(this, action, syncContext); } }
/// <summary> /// Adds a callback to be executed each time progress value changes. If the operation is completed <paramref name="callback"/> /// is invoked on the <paramref name="syncContext"/> specified. /// </summary> /// <remarks> /// The <paramref name="callback"/> is invoked on a <see cref="SynchronizationContext"/> specified. Throwing an exception from the callback might cause unspecified behaviour. /// </remarks> /// <param name="callback">The callback to be executed when the operation progress value has changed.</param> /// <param name="syncContext">If not <see langword="null"/> method attempts to marshal the continuation to the synchronization context. /// Otherwise the callback is invoked on a thread that initiated the operation completion. /// </param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="callback"/> is <see langword="null"/>.</exception> /// <exception cref="ObjectDisposedException">Thrown is the operation has been disposed.</exception> public void AddProgressCallback(IProgress <float> callback, SynchronizationContext syncContext) { ThrowIfDisposed(); if (callback == null) { throw new ArgumentNullException(nameof(callback)); } if (!TryAddCallback(callback, syncContext, false)) { CallbackUtility.InvokeProgressCallback(this, callback, syncContext); } }
public void InvokeProgressCallbacks() { if (_progressCallback1 != null) { CallbackUtility.InvokeProgressCallback(_op, _progressCallback1, _sharedContext); } if (_progressCallbacks != null) { foreach (var item in _progressCallbacks) { CallbackUtility.InvokeProgressCallback(_op, item, _sharedContext); } } }
public void Invoke(bool invokeAsync) { if (_progressCallbacks != null) { foreach (var item in _progressCallbacks) { CallbackUtility.InvokeProgressCallback(_op, item.Callback, item.SyncContext); } } foreach (var item in this) { CallbackUtility.InvokeCompletionCallback(_op, item.Callback, item.SyncContext, invokeAsync); } }
private void InvokeProgressCallbacks() { var value = _callback; if (value != null) { if (value is CallbackCollection callbackList) { lock (callbackList) { callbackList.InvokeProgressCallbacks(); } } else { CallbackUtility.InvokeProgressCallback(this, value); } } }
public void Invoke(bool invokeAsync) { if (_progressCallback1 != null) { CallbackUtility.InvokeProgressCallback(_op, _progressCallback1, _sharedContext); } if (_progressCallbacks != null) { foreach (var item in _progressCallbacks) { CallbackUtility.InvokeProgressCallback(_op, item, _sharedContext); } } if (_completionCallback1 != null) { CallbackUtility.InvokeCompletionCallback(_op, _completionCallback1, _sharedContext, invokeAsync); } if (_completionCallback2 != null) { CallbackUtility.InvokeCompletionCallback(_op, _completionCallback2, _sharedContext, invokeAsync); } if (_completionCallback3 != null) { CallbackUtility.InvokeCompletionCallback(_op, _completionCallback3, _sharedContext, invokeAsync); } if (_completionCallbacks != null) { foreach (var item in _completionCallbacks) { CallbackUtility.InvokeCompletionCallback(_op, item, _sharedContext, invokeAsync); } } }
private void InvokeProgressChangedInline(object callback) { Debug.Assert(callback != null); CallbackUtility.InvokeProgressCallback(_op, callback); }