Progress feedback from Service Agent

Feb 19, 2014 at 5:30 AM
Edited Feb 19, 2014 at 5:30 AM
I've been following the samples you provided with the toolkit however I'm struggling to figure out how to do progress feedback through/from a service agent back to my View that binds to props on my VM.

In my VM I have:
// Call service agent with completion callback 
serviceAgent.DoImport
  (
      _connectionString, type, Filename, _clientname, (intresult, error) => ImportCompleted(intresult, error)
  );
In my service agent interface I have:
void DoImport(string connectionString, string type, string filename, string _clientname,   Action<IntegrationResult, Exception> action);
In my service agent I have:
var bw = new BackgroundWorker();

bw.DoWork += (s, ea) =>
    {
        ea.Result = mi.Invoke(null, new object[] { connectionstring, filename, clientname });
    };

bw.RunWorkerCompleted += (s, ea) =>
    {
        if (ea.Error != null)
        {
            completed(null, ea.Error);
        }
        else
        {
            completed((IntegrationResult)ea.Result, null);
        }
    };

bw.RunWorkerAsync();
Thanks in advance.
Feb 19, 2014 at 9:02 PM
This should be fairly straightforward. Background Worker has an event you can fire to report progress. You can mirror that in your service agent by exposing a similar event, then firing it in a handler for the bw progress event. You can report progress from bw based on whatever you're doing, if there are chunks of work, or simply by using a timer.

Instead of adding events to your service agent, you can add another Action parameter to your DoImport method, which your service agent method invokes to report progress.

Hope this helps.

Cheers,
Tony