我正在尝试建立一个程序来帮助我的医疗图表。这一切都很顺利,调试只需3-4秒即可启动。今天当我开始工作时,花了整分钟来启动调试。这个简单的代码看起来不合理。我运行了Performance Profiler,看起来大部分时间花在解析MainWindow上。 Pic of Performace Profiler. 还有另一个窗口从程序中的上下文菜单选项打开,它用于立即打开,但现在打开需要10秒钟。
我在这里做错了吗?
XAML代码 -
<Window x:Name="Form1" x:Class="ChiroHelp_3._1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=system"
xmlns:local="clr-namespace:ChiroHelp_3._1"
mc:Ignorable="d"
Title="ChiroHelp 3.1" Height="970" Width="1338" MinHeight="970" MinWidth="1200" WindowStartupLocation="CenterScreen">
<Grid>
<TabControl x:Name="TabControlSOAP" HorizontalAlignment="Left" Height="923" Margin="5,5,0,0" VerticalAlignment="Top" Width="822">
<TabItem x:Name="TabSubjective" Header="Subjective">
<Grid Background="#FFFFFFFF">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TabControl HorizontalAlignment="Left" Height="898" VerticalAlignment="Top" Width="822" Margin="-3,0,-3,-1">
<TabItem x:Name="TabHPI" Header="HPI">
<Grid>
<TextBox x:Name="textBoxSubAddyo" TextWrapping="Wrap" Text="52" Margin="10,10,785,840"/>
<Label Content="year old" Margin="35,10,728,840" RenderTransformOrigin="0.5,0.5" Padding="1"/>
<ComboBox x:Name="comboBoxSubAddyoM" HorizontalAlignment="Left" Height="20" Margin="88,10,0,0" VerticalAlignment="Top" Width="64" Padding="4,1,1,1">
<ComboBoxItem Content="male "/>
<ComboBoxItem Content="female "/>
</ComboBox>
<ComboBox x:Name="comboBoxSubAddyoP" HorizontalAlignment="Left" Height="20" Margin="157,10,0,0" VerticalAlignment="Top" Width="64" Padding="4,1,1,1">
<ComboBoxItem Content="PTC "/>
<ComboBoxItem Content="RTC "/>
</ComboBox>
<Label Content="for" Margin="226,10,571,840" RenderTransformOrigin="0.5,0.5" Padding="1"/>
<ComboBox x:Name="comboBoxSubAddyoE" HorizontalAlignment="Left" Height="20" Margin="250,10,0,0" VerticalAlignment="Top" Width="197" Padding="4,1,1,1">
<ComboBoxItem Content=""/>
<ComboBoxItem Content="evaluation and management of "/>
</ComboBox>
<Button x:Name="SubAddyo" Content="Add" HorizontalAlignment="Left" Height="20" Margin="452,10,0,0" VerticalAlignment="Top" Width="56" Click="SubAddyo_Click" Focusable="False"/>
<Button Content="LOCQSMAT" HorizontalAlignment="Left" Height="20" Margin="10,64,0,0" VerticalAlignment="Top" Width="78"/>
<Button Content="Thyroid Symptoms:" HorizontalAlignment="Left" Height="20" Margin="10,113,0,0" VerticalAlignment="Top" Width="118"/>
<Button Content="Diabetes" HorizontalAlignment="Left" Height="20" Margin="10,138,0,0" VerticalAlignment="Top" Width="56"/>
<Label Content="year old" Margin="13,39,750,811" RenderTransformOrigin="0.5,0.5" Padding="1"/>
<Label Content="year old" Margin="13,89,750,761" RenderTransformOrigin="0.5,0.5" Padding="1"/>
</Grid>
</TabItem>
<TabItem x:Name="TabROS" Header="ROS"/>
</TabControl>
</Grid>
</TabItem>
<TabItem x:Name="TabObjective" Header="Objective">
<Grid Background="#FFFFFFFF">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TabControl HorizontalAlignment="Left" Height="898" VerticalAlignment="Top" Width="822" Margin="-3,0">
<TabItem x:Name="TabMusculoskeletal" Header="Musculoskeletal">
<Grid Background="#FFFFFFFF">
<TabControl HorizontalAlignment="Left" Height="871" VerticalAlignment="Top" Width="822" Margin="-3,1,-3,-1">
<TabItem x:Name="TabJtPalpation" Header="Jt Palpation"/>
<TabItem x:Name="TabMslPalpation" Header="Msl Palpation"/>
<TabItem x:Name="TabCx" Header="Cx Exam"/>
<TabItem x:Name="TabTx" Header="Tx Exam"/>
<TabItem x:Name="TabLx" Header="Lx/SI Exam"/>
<TabItem x:Name="TabHA" Header="HA Exam"/>
<TabItem x:Name="TabShoulder" Header="Shoulder Exam"/>
<TabItem x:Name="TabKnee" Header="Knee Exam"/>
</TabControl>
</Grid>
</TabItem>
<TabItem x:Name="TabOther" Header="Other"/>
</TabControl>
</Grid>
</TabItem>
<TabItem x:Name="TabAssessment" Header="Assessment"/>
<TabItem x:Name="TabPlan" Header="Plan"/>
</TabControl>
<RichTextBox x:Name="RichTextBoxSoapPreview" Margin="832,27,8,61" AcceptsTab="True" AcceptsReturn="True" FontFamily="Microsoft Sans Serif" FontSize="11" UndoLimit="1000" ContextMenuOpening="SOAPContextMenuOpening" TextChanged="RichTextBoxSoapPreview_TextChanged" SelectionChanged="RichTextBoxSoapPreview_SelectionChanged" SpellCheck.IsEnabled="True">
<SpellCheck.CustomDictionaries>
<sys:Uri>pack://application:,,,/MedDic.lex</sys:Uri>
</SpellCheck.CustomDictionaries>
<RichTextBox.ContextMenu>
<ContextMenu>
</ContextMenu>
</RichTextBox.ContextMenu>
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/>
</Style>
</RichTextBox.Resources>
<FlowDocument>
<Paragraph>
<Run FontWeight="Bold" Text="Subjective:"/>
</Paragraph>
<Paragraph/>
<Paragraph/>
<Paragraph>
<InlineUIContainer x:Name="ROSContainer">
<TextBlock x:Name="TextBlockROS" Background="LightBlue" HorizontalAlignment="Left" TextWrapping="Wrap" UseLayoutRounding="True" VerticalAlignment="Top" d:DesignUseLayoutRounding="True" ><Run Text="@ROS@"/></TextBlock>
</InlineUIContainer>
</Paragraph>
<Paragraph/>
<Paragraph>
<Run FontWeight="Bold" Text="Objective:"/>
</Paragraph>
<Paragraph>
<InlineUIContainer x:Name="ObjectiveContainer">
<TextBlock x:Name="TextBlockObjective" Background="LightBlue" HorizontalAlignment="Left" TextWrapping="Wrap" UseLayoutRounding="True" VerticalAlignment="Top" d:DesignUseLayoutRounding="True"><Run Text="@Objective@"/></TextBlock>
</InlineUIContainer>
</Paragraph>
<Paragraph/>
<Paragraph>
<Run FontWeight="Bold" Text="Assessment:"/>
</Paragraph>
<Paragraph>
<InlineUIContainer x:Name="AssessmentContainer">
<TextBlock x:Name="TextBlockAssessment" Background="LightBlue" HorizontalAlignment="Left" TextWrapping="Wrap" UseLayoutRounding="True" VerticalAlignment="Top" d:DesignUseLayoutRounding="True"><Run Text="@Assessment@"/></TextBlock>
</InlineUIContainer>
</Paragraph>
<Paragraph/>
<Paragraph>
<Run FontWeight="Bold" Text="Plan:"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
<Grid HorizontalAlignment="Left" Height="22" Margin="832,0,0,0" VerticalAlignment="Top" Width="488">
<ToggleButton x:Name = "ToggleButtonBold" Content = "B" Command="EditingCommands.ToggleBold" CommandTarget="{Binding ElementName=RichTextBoxSoapPreview}" Margin = "0,0,465,0" FontWeight="Bold" />
<ToggleButton x:Name = "ToggleButtonItalic" Content = "I" Command="EditingCommands.ToggleItalic" CommandTarget="{Binding ElementName=RichTextBoxSoapPreview}" Margin = "28,0,437,0" FontStyle="Italic" />
<ToggleButton x:Name = "ToggleButtonUnderline" Content = "U" Command="EditingCommands.ToggleUnderline" CommandTarget="{Binding ElementName=RichTextBoxSoapPreview}" Margin = "56,0,409,0" />
<Button x:Name="ButtonInsertROS" Content="ROS" HorizontalAlignment="Left" Margin="130,0,0,0" VerticalAlignment="Top" Width="75" Click="ButtonInsertROS_Click"/>
<Button x:Name="ButtonInsertObjective" Content="Objective" HorizontalAlignment="Left" Margin="210,0,0,0" Width="75" Height="20" VerticalAlignment="Top" Click="ButtonInsertObjective_Click"/>
<Button x:Name="ButtonInsertAssessment" Content="Assessment" HorizontalAlignment="Left" Margin="290,0,0,0" VerticalAlignment="Top" Width="75" Click="ButtonInsertAssessment_Click"/>
</Grid>
</Grid>
更新 - 我浏览了XAML代码注释和取消注释部分。看起来问题出在......
<SpellCheck.CustomDictionaries>
<sys:Uri>pack://application:,,,/MedDic.lex</sys:Uri>
</SpellCheck.CustomDictionaries>
当我评论此部分时,它会在107ms内加载,当我取消注释此部分时需要52秒。我有的MedDic.lex文件是一个非常大的医学词典。我删除了字典中除了两个单词之外的所有单词,问题仍然存在。
我是否正确添加了自定义词典?为什么要解析这么长时间?
答案 0 :(得分:0)
我也遇到过这个问题,因为重新启动Visual Studio解决了这个问题。
答案 1 :(得分:0)
我建议:
执行“清洁解决方案”
关闭解决方案文件和Visual Studio
删除bin和obj目录
删除.vs目录
再次尝试调试
答案 2 :(得分:0)
原来代码很好。我在另一台计算机上尝试过,它按预期工作。我在电脑上重新安装了Windows,事情又恢复了正常。仍然不确定发生了什么,但修复了它。