private void startButton_Click(object sender, RoutedEventArgs e) { int roomId; if (!int.TryParse(roomIdTextBox.Text, out roomId)) { MessageBox.Show("直播间编号范围必须为 " + DanMuListener.MinRoomId + "~" + DanMuListener.MaxRoomId); return; } if (roomId < DanMuListener.MinRoomId || roomId > DanMuListener.MaxRoomId) { MessageBox.Show("直播间编号范围必须为 " + DanMuListener.MinRoomId + "~" + DanMuListener.MaxRoomId); return; } danMuListener = new DanMuListener(roomId); danMuListener.Start(); danMuListener.Message += danMuListener_Message; danMuListener.OnlineCountUpdate += danMuListener_OnlineCountUpdate; danMuListener.RoomBlockInto += danMuListener_RoomBlockInto; danMuListener.RoomBlockMessage += danMuListener_RoomBlockMessage; danMuListener.RoomSlientOn += danMuListener_RoomSlientOn; danMuListener.RoomSlientOff += danMuListener_RoomSlientOff; danMuListener.Error += danMuListener_Error; startButton.IsEnabled = false; stopButton.IsEnabled = true; roomIdTextBox.IsEnabled = false; }
private void danMuListener_Error(object sender, DanMuListenerErrorEventArgs e) { ListBoxItem item = new ListBoxItem(); item.Content = e.Exception; item.CommandBindings.Add(danMuCopyCmdBinding); item.ContextMenu = danMuItemContextMenu; danmuListBox.Items.Add(item); danMuListener.Start(); }
static void Main(string[] args) { List <DanMuListener> list = new List <DanMuListener>(); for (int i = 0; i < 1000; i++) { DanMuListener listener = new DanMuListener(0); listener.Start(); list.Add(listener); } Console.WriteLine(">_<"); Console.ReadLine(); foreach (var item in list) { item.Stop(); } System.Threading.Thread.Sleep(1000 * 10); Console.WriteLine("End"); }