0

I have the following code to connect to MYOB's SDK

    var cfsCloud = new CompanyFileService(_configurationCloud, null, _oAuthKeyService);
    cfsCloud.GetRange(OnComplete, OnError);

where

private  void OnComplete(HttpStatusCode statusCode, CompanyFile[] companyFiles)
    {  // ask for credentials etc }

I want to convert this to use a TaskCompletionSource like this example

however my OnComplete has multiple parameters. How do I code that?

Community
  • 1
  • 1
Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • 1
    The [SDK](https://www.nuget.org/packages/MYOB.AccountRight.API.SDK/) for Accountright API supports async/await i.e. [GetRangeAsync](https://github.com/MYOB-Technology/AccountRight_Live_API_.Net_SDK/blob/master/MYOB.API.SDK/SDK/Services/CompanyFileService.cs#L53) – Shaun Wilde Sep 01 '15 at 23:49
  • Augh! I have tripped up on that before. Care to put it as the answer? – Kirsten Sep 02 '15 at 00:32

1 Answers1

2

As mentioned in the comment

The SDK for Accountright API supports async/await i.e. GetRangeAsync

so you can do something like this if you wanted/needed to wrap it in a TaskCompletionSource

static Task<CompanyFile[]> DoWork()
{
    var tcs = new TaskCompletionSource<CompanyFile[]>();
    Task.Run(async () =>
    {
        var cfsCloud = new CompanyFileService(_configurationCloud, null, _oAuthKeyService);
        var files = await cfsCloud.GetRangeAsync();
        tcs.SetResult(files);
    });
    return tcs.Task;
}
Shaun Wilde
  • 8,228
  • 4
  • 36
  • 56