Developer

Timer

The Timer object allows you to measure the duration of an application operation. The duration is logged with the timestamp of the event and a key value that can be used for filtering analytics.

There are two ways developers can handle the Timer object:
  • Call the static void TimeStart (string key) and static IAsyncAction/Task (string key) APIs. The library stores the Timer object, which is invisible to the application developer. The library keeps the timer in memory and persists it into the secure store when static IAsyncAction/Task TimeEndAsync(string key) is called. The key is mandatory and must be unique for each timer.
  • Call the static Timer MakeTimer(string key) API, which creates a timer instance and returns to the application layer. The application stores the timer; the library does not keep references to it. To stop and persist the timer, the application calls static IAsyncAction/Task StopTimerAsync(Timer timer). The key can be empty or duplicated.

The API timer is an object with a timestamp and a method to stop the timer, which sets the timer interval to the current time and saves the duration. After the timer stops, the Timer object is saved in the secure store.

Example

The developer wants to know how long it takes to download a very large file.

Create a timer before starting the download, then call TimeEndAsync when finished.

Usage.TimeStart ("DownloadTimer")
var downloadedFile = await GetHugeFileAsync();
await Usage.TimeEndAsync("DownloadTimer”);

The library generates a record that POSTs to the server:

{
	"type":"timer",
	"key":"DownloadTimer",
	"info":{
		"start":"2014-10-27T09:05:39.215Z",
		"duration":"10.6092"},
	"appSessionId":"",
	"userSessionId":"4dbcb6fa-7608-4430-bade-128f41a2f614",
	"timestamp":"2014-10-27T09:05:49.825Z"
}