Esempio n. 1
0
        public void Test()
        {
            ThreadLocal <string> sender = new ThreadLocal <string>(
                () => $"{messageSubjects[random.Next(messageSubjects.Length)]} film");

            Action action = () =>
            {
                Thread.Sleep(random.Next(_timeRange));

                using (ChatBotClient client = new ChatBotClient("brovie---film-chat-bot.herokuapp.com", "do"))
                {
                    ChatMessage message  = ChatMessageFactory.ChatMessageToSend(sender.Value);
                    ChatMessage received = client.PostMessage(message);
                    _output.AddFromEnumerable(new[] { $"{sender.Value} -> {received.MessageText}" });
                }
            };

            Action[] threads = new Action[_connectionNumber];
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = action;
            }

            Parallel.Invoke(threads);
        }