Click here to Skip to main content
15,894,646 members
Articles / Desktop Programming / Windows Forms

A New Way to Approach APM in .NET

Rate me:
Please Sign up or sign in to vote.
4.73/5 (9 votes)
18 Jun 2009CPOL4 min read 27.1K   98   33  
A wrapper for the Asynchronous Progamming Model in .NET
using System;
using System.Windows.Forms;

namespace ApmHelperWinformsExample
{
    /// <summary>
    /// example if you have more parms than Func<> allows
    /// </summary>
    public partial class ApmHelperExample2 : Form
    {

        private readonly ApmHelper<Parms, double> _helper;
        public ApmHelperExample2()
        {
            
            InitializeComponent();
            this._helper = new ApmHelper<Parms, double>(Go);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var parms = new Parms {a = 1, b = 2, c = 3, d = 4};
            this._helper.InvokeAsync(parms, this.Callback);

        }

        private void Callback(double d)
        {
            
        }

        private static double Go(Parms parms)
        {
            return SomeWebServiceMaybe.SomeLongRunningAddFunction(parms.a, parms.b, parms.c, parms.d);
        }

        private class Parms
        {
            public int a, b, c, d;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions