コード例 #1
0
        public async Task RunTask(ClientClass cc, string taskNumber)
        {
            int count = 0;

            while (count < 1000)
            {
                await cc.SendMessage($"{GetCurrentDateTime()} This is a test message {count.ToString()} from the client {taskNumber}.");

                await Task.Delay(2);

                count++;
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var  client   = new ClientClass();
            Task clpmTask = Task.Run(() => client.ClientPipeMonitor());

            Program p = new Program();

            tasks.Add(p.RunTask(client, "1"));
            tasks.Add(p.RunTask(client, "2"));
            tasks.Add(p.RunTask(client, "3"));
            tasks.Add(p.RunTask(client, "4"));

            Console.ReadKey();
        }
コード例 #3
0
        static async Task Main(string[] args)
        {
            var client = new ClientClass();
            await client.ClientPipeMonitor(true);

            Task clpmTask = Task.Run(() => client.ClientPipeMonitor()); // Hacky, but this will monitor for any pipe disconnects

            int    count   = 0;
            string message = string.Empty;

            while (true)
            {
                var key = Console.ReadKey();
                if (key.KeyChar == 'a')
                {
                    Console.WriteLine($"[{key.KeyChar}] was pressed.");
                    break;
                }
                count   = 0;
                message = string.Empty;
                Console.WriteLine($"Sending messages. [{key.KeyChar}] was pressed.");
                while (count < 1000)
                {
                    message = $"{GetCurrentDateTime()} This is a test message {count.ToString()} from the client.";
                    Console.WriteLine(message);
                    client.SendMessage(message);
                    await Task.Delay(1);

                    count++;
                }
            }

            Console.WriteLine("Completed sending messages");

            Console.ReadKey();
        }