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); }
private void AddToMessages(ChatMessage chatMessage) { _messages.Add(chatMessage); MessageBox.Text = string.Empty; var response = Client.PostMessage(chatMessage); _messages.Add(response); int lastMessageIndex = MessagesListBox.Items.Count - 1; MessagesListBox.ScrollIntoView(MessagesListBox.Items[lastMessageIndex]); }