Closed hughmullally closed 6 years ago
Have you got an example of what you are trying to run?
Thanks for replying so quickly. Here is the code:
using System.Diagnostics;
using CompaniesHouse;
using CompaniesHouse.Request;
namespace CompaniesHouseApi
{
class Program
{
private static string ChKey = "TM4vsfrlRKop0jVbzZK0V4l1OmtluusevXMQLFpW";
private static CompaniesHouseSettings Settings { get; set; }
static void Main(string[] args)
{
ProcessRequest();
}
private static async void ProcessRequest()
{
Settings = new CompaniesHouseSettings(ChKey);
using (var client = new CompaniesHouseClient(Settings))
{
var request = new SearchRequest()
{
Query = "SpecSavers",
StartIndex = 10,
ItemsPerPage = 10
};
var result = await client.SearchAllAsync(request);
foreach (var item in result.Data.Items)
{
Debug.Print(item.Kind);
}
}
}
}
}
You need to change your Main method to return a Task:
static async Task Main(string[] args)
{
await ProcessRequest();
}
However you will need to be using C# 7.1, More info on this can be found here - https://blogs.msdn.microsoft.com/mazhou/2017/05/30/c-7-series-part-2-async-main/
Perfect. I was using VS2017, but for some reason the 4.7.1 runtime wasn't available. I downloaded that, made the code changes you suggested, and my initial test program works fine.
Thanks very much for your help and the quick responses.
Glad you got it working! Any other problems just open another issue.
I'm having a problem running your sample code. When function SearchAllAsync is called (with the await keyboard), it does'nt return to the following statement in that function, but to the next statement in the calling function. No exception is thrown.
I'm sure I'm doing something really dumb (probably to do with the async code), but it would help to have a simple full working example that I could try running.
I'm using Visual Studio 2017, .net framework 4.5.2 and CompaniesHouse.net 3.2,1