Exemplo n.º 1
0
    /// <summary>
    /// Call the operation, and then handle completion.
    /// </summary>
    /// <typeparam name="TData">Input data type to pass to operation.</typeparam>
    /// <param name="datafunction">Collection of operation to be called by AsyncOperation, and its input functions.</param>
    /// <param name="asyncOp">Operation making call.</param>
    private void AsyncOperationAction <TData>(DataAndAction <TData> datafunction, AsyncOperation asyncOp)
    {
        // Will have to do exception handling itself.
        TEventArgs args = datafunction.operation(datafunction.data, datafunction.action, false, asyncOp.UserSuppliedState, datafunction.funcEvent);

        this.AsyncWorkCompletionResult(args, asyncOp);
    }
Exemplo n.º 2
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);
    }