-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresponses.cs
47 lines (38 loc) · 1.23 KB
/
responses.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Honeycomb;
public class ResponsesExample
{
static void ReadResponses (ResponseCollection responses)
{
Response res;
while (responses.TryTake (out res, -1))
Console.WriteLine (res);
}
static void Main ()
{
string writeKey = "abcabc123123defdef456456";
string dataSet = "responses";
var honey = new LibHoney (writeKey, dataSet);
var responses = honey.Responses;
Task.Run (() => ReadResponses (responses));
var tasks = new Task [8];
foreach (int i in Enumerable.Range (0, tasks.Length)) {
var t = Task.Run (async () => {
// Simulate work.
var start = DateTime.Now;
await Task.Delay (new Random ().Next (100));
// Work is done, send the task id and its elapsed time.
var ev = new Event (honey);
ev.AddField ("id", i);
ev.AddField ("elapsed", (DateTime.Now - start).TotalMilliseconds);
ev.Send ();
});
tasks [i] = t;
}
Task.WaitAll (tasks);
honey.Close ();
}
}