예제 #1
0
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            Stopwatch watch = Stopwatch.StartNew();

            ServiceEventSource.Current.ServiceMessage(Context, "Generating 1000 random messages");

            await randomGenerator.Fill(1000);

            ServiceEventSource.Current.ServiceMessage(Context, "Generating random messages completed in " + watch.Elapsed);

            while (true)
            {
                cancellationToken.ThrowIfCancellationRequested();

                await PublishRandom();

                await Task.Delay(TimeSpan.FromMilliseconds(200), cancellationToken);
            }
        }