Asynchronous Execution of Operations

Asynchronous Execution of Operations

Every call from the Backend Services .NET SDK to Telerik Platform can be made either synchronously or asynchronously. This applies to any type of server request—reading data, registering a user, sending a push notification, and so on.

Calling an SDK method that works with the server creates a request, but does execute it.

EverliveApp myApp = new EverliveApp("your-app-id");
var getAllUsersRequest = myApp.WorkWith().Users().GetAll();

You must invoke one of the available Execute methods to execute a request. These are covered in the section below. For the sake of clarity, all examples below save you the creation of the request and only give the execution part.

Using the Async and Await Keywords

.NET provides the await and async keywords to control the synchronicity of execution. It is the recommended method as long as it is supported by your target .NET framework.

var allUsers = await getAllUsersRequest.ExecuteAsync();

Asynchronous Execution Using Callbacks

It is possible to execute a request to Telerik Platform asynchronously by providing a callback.

getAllUsersRequest.Execute(
    delegate(IEnumerable<User> allUsers) {

    }
)

Synchronous Execution

The SDK provides a way to execute operations synchronously. Such executions block the current thread until a response from the server is received.

var allUsers = getAllUsersRequest.ExecuteSync();

Optionally, you can specify a timeout when invoking ExecuteSync. The best practices suggest that you never invoke operations synchronously in the UI thread, because this will block the UI and the app will stay unresponsive until the response comes.

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.