/// <summary> /// Perform bogus work /// </summary> public Task<WorkResult> DoWork(WorkSlice slice) { var start = DateTime.UtcNow; var result = new List<ulong>(capacity: 100); int primes = 0; ulong max = 0; // Naively check if slice contains any prime numbers for (ulong i = slice.Start; i <= slice.End; ++i) { if (IsPrime(i)) { // Report prime to stream max = i; ++primes; } } // Calculate diagnostics & results var end = (DateTime.UtcNow - start); var duration = end.TotalSeconds; var testsPerSecond = slice.Size / duration; var primesPerSecond = primes / duration; return Task.FromResult( new WorkResult { MaxPrime = max, PrimesPerSecond = primesPerSecond, TestsPerSecond = testsPerSecond }); }
public Task Start(WorkSlice slice) { var task = GrainFactory.GetGrain<IWorker>(0) .DoWork(slice) .ContinueWith(t => SignalReady(t.Result)); task.ConfigureAwait(false); return TaskDone.Done; }