public IDisposable RegisterTimer(Func <object, Task> callback, object state, TimeSpan dueTime, TimeSpan period) { var registration = new TimerRegistration(callback, state, dueTime, period); this.Registrations.Add(registration); return(registration.Disposable); }
internal IDisposable Register(Action <object> callback, object state) { Contract.Assert(callback != null); var registration = new TimerRegistration(callback, state); lock (_addLock) { _newRegistrations.AddLast(registration); } return(registration); }
public object Register(Action <object> callback, object state) { var registration = new TimerRegistration(callback, state); lock (_registrations) { _registrations.Add(registration); } return(registration); }
private static void Purge(LinkedList <TimerRegistration> registrations) { LinkedListNode <TimerRegistration> nextNode; LinkedListNode <TimerRegistration> currentNode = registrations.First; while (currentNode != null) { nextNode = currentNode.Next; TimerRegistration registration = currentNode.Value; if (registration.Disposed) { registrations.Remove(currentNode); } currentNode = nextNode; } }
private void InvokeCallbacks(LinkedList <TimerRegistration> registrations) { LinkedListNode <TimerRegistration> nextNode = registrations.First; while (nextNode != null) { TimerRegistration registration = nextNode.Value; try { registration.InvokeCallback(); } catch (Exception ex) { _trace.WriteError(Resources.Trace_TimerCallbackException, ex); } nextNode = nextNode.Next; } }
/// <summary> /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"/> contains a specific value. /// </summary> /// <returns> /// true if <paramref name="item"/> is found in the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false. /// </returns> /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param> public bool Contains(TimerRegistration item) { return(this.Registrations.Contains(item)); }
/// <summary> /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </summary> /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.</exception> public void Add(TimerRegistration item) { this.Registrations.Add(item); }
/// <summary> /// Inserts an item to the <see cref="T:System.Collections.Generic.IList`1"/> at the specified index. /// </summary> /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param><param name="item">The object to insert into the <see cref="T:System.Collections.Generic.IList`1"/>.</param><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1"/>.</exception><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.IList`1"/> is read-only.</exception> public void Insert(int index, TimerRegistration item) { this.Registrations.Insert(index, item); }
/// <summary> /// Determines the index of a specific item in the <see cref="T:System.Collections.Generic.IList`1"/>. /// </summary> /// <returns> /// The index of <paramref name="item"/> if found in the list; otherwise, -1. /// </returns> /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.IList`1"/>.</param> public int IndexOf(TimerRegistration item) { return(this.Registrations.IndexOf(item)); }
/// <summary> /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </summary> /// <returns> /// true if <paramref name="item"/> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false. This method also returns false if <paramref name="item"/> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </returns> /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.</exception> public bool Remove(TimerRegistration item) { return(this.Registrations.Remove(item)); }
internal IDisposable Register(Action<object> callback, object state) { Contract.Assert(callback != null); var registration = new TimerRegistration(callback, state); lock (_addLock) { _newRegistrations.AddLast(registration); } return registration; }