예제 #1
0
 /// <summary>
 /// Implementation of asynchronous function called by sub-classes with appropriate action and function parameters
 /// to perform the asynchronous operation, and turn results into TEventArgs.
 /// This override just defaults the userState object to null.
 /// </summary>
 /// <typeparam name="TData">Input data type of operation.</typeparam>
 /// <param name="data">Operation input data.</param>
 /// <param name="operation">Operation being called in another thread by AsyncOperation.</param>
 /// <param name="actionProxy">Action being called.</param>
 /// <param name="funcEvent">Function to create TEventArgs from results.</param>
 public void AsyncActionImpl <TData>(TData data
                                     , AsyncOperationActionDefaultDelegate <TData> operation
                                     , Action <TData> actionProxy
                                     , MakeActionEventDelegate <TData> funcEvent)
 {
     this.AsyncActionImpl(null, data, operation, actionProxy, funcEvent);
 }
예제 #2
0
 /// <summary>
 /// Implementation of asynchronous function called by sub-classes with appropriate action and function parameters
 /// to perform the asynchronous operation, and turn results into TEventArgs.
 /// This overload requires no operation delegate specified for AsyncOperation.
 /// </summary>
 /// <typeparam name="TData">Input data type of operation.</typeparam>
 /// <param name="data">Operation input data.</param>
 /// <param name="operation">Operation being called in another thread by AsyncOperation.</param>
 /// <param name="actionProxy">Action being called.</param>
 /// <param name="funcEvent">Function to create TEventArgs from results.</param>
 public void AsyncActionImpl <TData>(object userState
                                     , TData data
                                     , Action <TData> actionProxy
                                     , MakeActionEventDelegate <TData> funcEvent
                                     )
 {
     this.AsyncActionImpl(userState, data, AsyncOperationActionDefaultImpl, actionProxy, funcEvent);
 }
예제 #3
0
    // Implementation defined in sub-class.

    /// <summary>
    /// Implementation of asynchronous function called by sub-classes with appropriate action and function parameters
    /// to perform the asynchronous operation, and turn results into TEventArgs.
    /// </summary>
    /// <typeparam name="TData">Input data type of operation.</typeparam>
    /// <param name="userState">User state object provided by calling code.</param>
    /// <param name="data">Operation input data.</param>
    /// <param name="operation">Operation being called in another thread by AsyncOperation.</param>
    /// <param name="actionProxy">Action being called.</param>
    /// <param name="funcEvent">Function to create TEventArgs from results.</param>
    public void AsyncActionImpl <TData>(object userState
                                        , TData data
                                        , AsyncOperationActionDefaultDelegate <TData> operation
                                        , Action <TData> actionProxy
                                        , MakeActionEventDelegate <TData> funcEvent
                                        )
    {
        AsyncOperation        asyncOp    = this.CreateOperation(userState);
        DataAndAction <TData> dataaction = new DataAndAction <TData>
        {
            operation = operation,
            data      = data,
            action    = actionProxy,
            funcEvent = funcEvent
        };
        AsyncOperationActionDelegate <TData> asyncDelegate = this.AsyncOperationAction <TData>;

        asyncDelegate.BeginInvoke(dataaction, asyncOp, null, null);
    }
예제 #4
0
    public static TEventArgs AsyncOperationActionDefaultImpl <TData>(TData data, Action <TData> action, bool cancelled, object userState,
                                                                     MakeActionEventDelegate <TData> funcEvent)
    {
        Exception e = null;

        try
        {
            action(data);
        }
        catch (Exception ex)
        {
            e = ex;
        }

        object userStateOriginal = userState;

        if (userState is UserStateHolder)
        {
            // Get the original user-provided object out of the holder.
            userState = ((UserStateHolder)userState).UserState;
        }

        return(funcEvent(data, e, cancelled, userState));
    }