view Implab/ICancelationToken.cs @ 143:16f926ee499d v2

DRAFT: refactoring, adding cancelation token
author cin
date Wed, 04 Mar 2015 18:05:39 +0300
parents
children 8c0b95069066
line wrap: on
line source

using System;

namespace Implab {
    public interface ICancelationToken {
        /// <summary>
        /// Indicates wherther the cancellation was requested.
        /// </summary>
        bool IsCancelRequested { get ; }

        /// <summary>
        /// The reason why the operation should be cancelled.
        /// </summary>
        Exception CancelReason { get ; }

        /// <summary>
        /// Accepts if requested.
        /// </summary>
        /// <returns><c>true</c>, if if requested was accepted, <c>false</c> otherwise.</returns>
        bool AcceptIfRequested();

        /// <summary>
        /// Sets the token to cancelled state.
        /// </summary>
        /// <param name="reason">The reason why the operation was cancelled.</param>
        void SetCancelled(Exception reason);

        /// <summary>
        /// Adds the listener for the cancellation request, is the cancellation was requested the <paramref name="handler"/>
        /// is executed immediatelly.
        /// </summary>
        /// <param name="handler">The handler which will be executed if the cancel occurs.</param>
        void CancellationRequested(Action<Exception> handler);

    }
}