Esempio n. 1
0
        static async Task StartClient(Socket sock, double sleepSeconds, Scoreboard scoreboard)
        {
            try {
                using (var stream = new NetworkStream(sock)) {
                    var buffer = new byte[1];
                    var hello  = ASCIIEncoding.ASCII.GetBytes("*");
                    while (true)
                    {
                        await stream.WriteAsync(hello, 0, 1);

                        var len = await stream.ReadAsync(buffer, 0, 1);

                        if (len == 0)
                        {
                            // server closed
                            break;
                        }
                        Trace.Assert(len == 1);
                        Trace.Assert(buffer[0] == hello[0]);

                        scoreboard.AddHit();

                        await Task.Delay(TimeSpan.FromSeconds(sleepSeconds));
                    }
                }
            } catch (Exception e) {
                FatalError(e);
            } finally {
                sock.Close();
            }
        }
Esempio n. 2
0
        static async Task WorkTask(Scoreboard scoreboard, double sleepSeconds)
        {
            while (true)
            {
                await Task.Delay(TimeSpan.FromSeconds(sleepSeconds));

                scoreboard.AddHit();
            }
        }
Esempio n. 3
0
        static async Task WorkTask(Scoreboard scoreboard, TimeSpan sleepDelay)
        {
#if !USE_TASK_RUN_LAMBDA
            // Start using the threadpool immediately
            await Task.Yield();
#endif
            while (true)
            {
                scoreboard.AddHit();
                await Task.Delay(sleepDelay);
            }
        }