private async Task MessageProcessingTask() { try { ChannelReader <LoggerJsonMessage> MessageReader = _MessageManager.Messages.Reader; while (await MessageReader.WaitToReadAsync(_CloseCancellationToken.Token).ConfigureAwait(false)) { while (MessageReader.TryRead(out LoggerJsonMessage Message)) { if (_CloseCancellationToken.IsCancellationRequested) { return; } string TabTitle = Message.GroupName ?? _LoggerGroupCache.ResolveGroupNameForCategoryName(Message.CategoryName); if (!_Tabs.TryGetValue(TabTitle, out DebugWindowTabPage Tab)) { lock (_Tabs) { if (!_Tabs.TryGetValue(TabTitle, out Tab)) { Tab = new DebugWindowTabPage(this, TabTitle); _Tabs.Add(TabTitle, Tab); Invoke(new MethodInvoker(() => { ToolStripMenuItem TabWindowMenuItem = new ToolStripMenuItem(Tab.Text) { Checked = true, CheckOnClick = true, Tag = Tab }; TabWindowMenuItem.CheckedChanged += OnTabWindowMenuItemCheckedChanged; WindowMenu.DropDownItems.Add(TabWindowMenuItem); TabContainer.TabPages.Add(Tab); _ConfigureTabAction?.Invoke(Tab); })); } } } Tab.AddMessage(SerializeMessageToJson(Message)); } } } catch (OperationCanceledException) { } }
private void OnTabWindowMenuItemCheckedChanged(object?sender, EventArgs e) { if (sender is ToolStripMenuItem TabWindowMenuItem) { DebugWindowTabPage Tab = (DebugWindowTabPage)TabWindowMenuItem.Tag; if (TabWindowMenuItem.Checked) { TabContainer.TabPages.Add(Tab); } else { TabContainer.TabPages.Remove(Tab); } } }