protected async void ButtonLookup_Click(object sender, EventArgs e) { TextBox2.Text = ""; try { IEventGrain grainRef = GrainClient.GrainFactory.GetGrain <IEventGrain>(NameTextBox.Text); var topThree = await grainRef.GetTopThree(); var s = new StringBuilder(); if (topThree.Count > 0) { s.AppendLine("First Place: " + topThree[0]); } if (topThree.Count > 1) // if this were real we would check for ties { s.AppendLine("Second Place: " + topThree[1]); } if (topThree.Count > 2) { s.AppendLine("Third Place: " + topThree[2]); } TextBox2.Text = s.ToString(); } catch (Exception exc) { while (exc is AggregateException) { exc = exc.InnerException; } TextBox2.Text = exc.ToString(); } }
private async Task GenChange(IEventGrain eventGrain, int count) { for (int i = 0; i < count; i++) { await eventGrain.Update(new Change { Name = "GenChangeTask", Value = i, When = DateTimeOffset.UtcNow }); } }
public Task Start() { // keep generating for at least 10 minutes DelayDeactivation(TimeSpan.FromMinutes(10)); // use different deterministic pseudo-random sequence for each grain random = new Random((int)this.GetPrimaryKeyLong()); if (!started) { started = true; // find event grain for this generator eventGrain = GrainFactory.GetGrain <IEventGrain>("event" + this.GetPrimaryKeyLong()); RegisterTimer(Generate, null, TimeSpan.FromSeconds(random.Next(20)), // start within 20 secs TimeSpan.FromSeconds(2 + random.NextDouble())); // one outcome about every 2.5 seconds } return(TaskDone.Done); }