Issue with SearchOrdersAsync

I have used previous versions of the Square SDK but now I am trying to transition to the Square API V2. I am able to make the following call successfully but my issue is that I need to wait for the call to finish. Being and asynch call my code continues and I have no way of knowing when the query has returned the results. How do I know when the query has returned a result so that I can use it?

client = new SquareClient.Builder()

var locationIds = new List<string>();

var states = new List<string>();

var stateFilter = new SearchOrdersStateFilter.Builder(states: states)

DateTime fromTime = DateTime.Now.AddHours(-36);
DateTime toTime = DateTime.Now;

var closedAt = new TimeRange.Builder()
  .StartAt(fromTime.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo))
  .EndAt(toTime.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo))

var dateTimeFilter = new SearchOrdersDateTimeFilter.Builder()

var filter = new SearchOrdersFilter.Builder()

var sort = new SearchOrdersSort.Builder(sortField: "CLOSED_AT")

var query = new SearchOrdersQuery.Builder()

var body = new SearchOrdersRequest.Builder()

SearchOrdersResponse result = null; ;
	result = await client.OrdersApi.SearchOrdersAsync(body: body);
        return result; //reakpointhere
catch (ApiException e)
	Console.WriteLine("Failed to make the request");
	Console.WriteLine($"Response Code: {e.ResponseCode}");
	Console.WriteLine($"Exception: {e.Message}");
	return result;
catch(Exception e2)
	return result;


I put a breakpoint " return result; //reakpointhere" when I call this task it returns immediately and the breakpoint gets hit a few seconds late. I need to call SearchOrdersAsync synchronously.

Hi @EdneyHolder welcome to the forums! If you truly want it synchronously, then there is a synchronous method (just SearchOrders instead of SearchOrdersAsync):

You could also do something with the result after the await call, and it wouldn’t occur until the SearchOrdersAsync had completed (like calling a function with the result and using it somehow).