Beispiel #1
0
    /// <summary>
    /// Call the operation, and then handle completion.
    /// </summary>
    /// <typeparam name="TData">Input data type to pass to operation.</typeparam>
    /// <typeparam name="TResult">Result data type for 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 AsyncOperationFunc <TData, TResult>(DataAndFunc <TData, TResult> datafunction, AsyncOperation asyncOp)
    {
        // Will have to do exception handling itself.
        TEventArgs args = datafunction.operation(datafunction.data, datafunction.func, false, asyncOp.UserSuppliedState, datafunction.funcEvent);

        this.AsyncWorkCompletionResult(args, asyncOp);
    }
Beispiel #2
0
    // Implementation defined in sub-class.

    /// <summary>
    /// Implementation of asynchronous function called by sub-classes with appropriate function parameters
    /// to perform the asynchronous operation, and turn results into TEventArgs.
    /// </summary>
    /// <typeparam name="TData">Input data type of operation.</typeparam>
    /// <typeparam name="TResult">Result 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="funcProxy">Function being called.</param>
    /// <param name="funcEvent">Function to create TEventArgs from results.</param>
    public void AsyncFuncImpl <TData, TResult>(object userState
                                               , TData data
                                               , AsyncOperationFuncDefaultDelegate <TData, TResult> operation
                                               , Func <TData, TResult> funcProxy
                                               , MakeFuncEventDelegate <TData, TResult> funcEvent
                                               )
    {
        AsyncOperation asyncOp = this.CreateOperation(userState);
        DataAndFunc <TData, TResult> datafunction = new DataAndFunc <TData, TResult>
        {
            operation = operation,
            data      = data,
            func      = funcProxy,
            funcEvent = funcEvent
        };
        AsyncOperationFuncDelegate <TData, TResult> asyncDelegate = this.AsyncOperationFunc <TData, TResult>;

        asyncDelegate.BeginInvoke(datafunction, asyncOp, null, null);
    }