Ejemplo n.º 1
0
 internal void Release(AsyncSynchronization <TTask> synchronization)
 {
     if (CurrentSynchronization == synchronization)
     {
         lock (Lock)
         {
             CurrentTask            = null;
             CurrentSynchronization = null;
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Acquires a synchronization object which should be disposed when the task is completed.
        /// </summary>
        /// <param name="taskFactory">The invocation of the method which should be synchronized.</param>
        /// <param name="task">The task which will return the synchronized result.</param>
        /// <returns>A synchronization object which should be disposed when the task is completed.</returns>
        public AsyncSynchronization <TTask> Acquire(Func <TTask> taskFactory, out TTask task)
        {
            AsyncSynchronization <TTask> synchronization = new AsyncSynchronization <TTask>(this);

            lock (Lock)
            {
                if (CurrentTask == null)
                {
                    CurrentTask            = taskFactory.Invoke();
                    CurrentSynchronization = synchronization;
                }
            }

            task = CurrentTask;

            return(synchronization);
        }