Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 4
0
        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;
            }
        }
Exemplo n.º 5
0
        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;
            }
        }
Exemplo n.º 6
0
 /// <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));
 }
Exemplo n.º 7
0
 /// <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);
 }
Exemplo n.º 8
0
 /// <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);
 }
Exemplo n.º 9
0
 /// <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));
 }
Exemplo n.º 10
0
 /// <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));
 }
Exemplo n.º 11
0
 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;
 }