user175084
user175084

Reputation: 4630

Asynchronous calling a method

Here is my old code to call an asyn function:

    public class Caller {

    public void Calculate(CalcParameters calcParameters, string sourceApp) {
        AsyncCaller caller = new AsyncCaller(_username, _password, new Token());
        caller.Calculated += new CalculatedHandler(OnCalculated);
        caller.calculate(sourceApp, calcParameters);
    }

    protected virtual void OnCalculated(object sender, CalculatedEventArgs e) {
        if (OnCalculatedEvent != null) OnCalculatedEvent(e);
    }

    public void calculate(string calcID, WebService.CalcParameters calcParams) {
        calculate(0, calcID, calcParams);
    }

    public void calculate(long callID, string calcID, WebService.CalcParameters calcParams) {
        try {
            lock(this) {
                Worker wsWorker = MakeCalculateWorker(callID, calcID, new OnCalculatedHandler(OnCalculated), calcParams);
                Thread wsThread = new Thread(new ThreadStart(wsWorker.calculate));
                wsThread.IsBackground = true;
                wsThread.Start();
            }
        } catch (Exception ex) {
            _log.WriteError(
            Assembly.GetExecutingAssembly().GetName().Name,
            this.GetType().Name,
            MethodBase.GetCurrentMethod().Name,
            _username,
            ex.Message);
            throw ex;
        }
    }
}

But now i need to do this using delegate and begininvoke..

Please can someone help me with this or give me some samples to read from.

Thanks

Upvotes: 0

Views: 128

Answers (1)

Daniel Wardin
Daniel Wardin

Reputation: 1858

Here is a MSDN example which explains how to use Asynchronous Delegates.

Read through it but also go through it step by step as if you were the program to understand it.

Asynchronous Delegates Programming Sample

Upvotes: 2

Related Questions