You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WPF客户端软件首次打开特定对话框卡顿100秒,求助排查原因

问题

客户系统中出现特殊问题:每次重启软件后首次打开特定对话框,软件会冻结100秒,本地测试无法复现。
附加调试后发现,WPF通过PresentationFramework调用MS.Internal.WpfWebRequestHelper发起了超时100秒的WebRequest,但业务代码中并未主动执行任何Web请求操作。

调用栈信息

file:///C:/Windows/system32/spool/drivers/color/sRGB%20Color%20Space%20Profile.icm

TimeOut 100000


    ntdll.dll!00007fffc8f246d4()    Unknown
    KernelBase.dll!00007fffc653f310()   Unknown
    WindowsBase.ni.dll!00007fff7073069e()   Unknown
    [Managed to Native Transition]  
    WindowsBase.dll!System.Windows.Threading.DispatcherSynchronizationContext.Wait(System.IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)  Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    mscorlib.dll!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle waitableSafeHandle, long millisecondsTimeout, bool hasThreadAffinity, bool exitContext)  Unknown
    mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext) Unknown
    System.dll!System.Net.FileWebRequest.GetResponse()  Unknown
>   PresentationCore.dll!MS.Internal.WpfWebRequestHelper.GetResponse(System.Net.WebRequest request) Unknown
    PresentationCore.dll!System.Windows.Media.ColorContext.Initialize(System.Uri profileUri, bool isStandardProfileUriNotFromUser)  Unknown
    PresentationCore.dll!System.Windows.Media.ColorContext.ColorContext(System.Windows.Media.PixelFormat pixelFormat)   Unknown
    PresentationCore.dll!System.Windows.Media.Imaging.BitmapSource.CreateCachedBitmap(System.Windows.Media.Imaging.BitmapFrame frame, System.Windows.Media.Imaging.BitmapSourceSafeMILHandle wicSource, System.Windows.Media.Imaging.BitmapCreateOptions createOptions, System.Windows.Media.Imaging.BitmapCacheOption cacheOption, System.Windows.Media.Imaging.BitmapPalette palette) Unknown
    PresentationCore.dll!System.Windows.Media.Imaging.BitmapFrameDecode.FinalizeCreation()  Unknown
    PresentationCore.dll!System.Windows.Media.Imaging.BitmapDecoder.SetupFrames(System.Windows.Media.Imaging.BitmapDecoder decoder, System.Collections.ObjectModel.ReadOnlyCollection<System.Windows.Media.Imaging.BitmapFrame> frames) Unknown
    PresentationCore.dll!System.Windows.Media.Imaging.BitmapDecoder.Frames.get()    Unknown
    PresentationCore.dll!System.Windows.Media.Imaging.BitmapFrame.CreateFromUriOrStream(System.Uri baseUri, System.Uri uri, System.IO.Stream stream, System.Windows.Media.Imaging.BitmapCreateOptions createOptions, System.Windows.Media.Imaging.BitmapCacheOption cacheOption, System.Net.Cache.RequestCachePolicy uriCachePolicy)    Unknown
    PresentationCore.dll!System.Windows.Media.ImageSourceConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)    Unknown
    PresentationFramework.dll!System.Windows.TemplateContent.TrySharingValue(System.Windows.DependencyProperty property, object value, string parentName, System.Xaml.XamlReader xamlReader, bool allowRecursive, out System.Windows.PropertyValue? sharedValue)    Unknown
    PresentationFramework.dll!System.Windows.TemplateContent.TrySharingProperty(System.Xaml.XamlReader xamlReader, System.Xaml.XamlType parentType, string parentName, MS.Utility.FrugalObjectList<System.Xaml.NamespaceDeclaration> previousNamespaces, out System.Windows.PropertyValue? sharedValue) Unknown
    PresentationFramework.dll!System.Windows.TemplateContent.ParseNode(System.Xaml.XamlReader xamlReader, System.Windows.TemplateContent.StackOfFrames stack, System.Collections.Generic.List<System.Windows.PropertyValue> sharedProperties, ref int nameNumber, out object newValue)  Unknown
    PresentationFramework.dll!System.Windows.TemplateContent.ParseNodes(System.Windows.TemplateContent.StackOfFrames stack, System.Collections.Generic.List<System.Windows.PropertyValue> sharedProperties, ref int nameNumber) Unknown
    PresentationFramework.dll!System.Windows.TemplateContent.ParseTree(System.Windows.TemplateContent.StackOfFrames stack, System.Collections.Generic.List<System.Windows.PropertyValue> sharedProperties, ref int nameNumber)  Unknown
    PresentationFramework.dll!System.Windows.TemplateContent.ParseXaml()    Unknown
    PresentationFramework.dll!System.Windows.FrameworkTemplate.Template.set(System.Windows.TemplateContent value)   Unknown
    System.Xaml.dll!MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(object inst, System.Xaml.XamlMember property, object value)  Unknown
    System.Xaml.dll!System.Xaml.XamlObjectWriter.Logic_ApplyPropertyValue(MS.Internal.Xaml.Context.ObjectWriterContext ctx, System.Xaml.XamlMember prop, object value, bool onParent)   Unknown
    System.Xaml.dll!System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentProperty(MS.Internal.Xaml.Context.ObjectWriterContext ctx)   Unknown
    System.Xaml.dll!System.Xaml.XamlObjectWriter.WriteEndMember()   Unknown
    PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.TransformNodes(System.Xaml.XamlReader xamlReader, System.Xaml.XamlObjectWriter xamlWriter, bool onlyLoadOneNode, bool skipJournaledProperties, bool shouldPassLineNumberInfo, System.Xaml.IXamlLineInfo xamlLineInfo, System.Xaml.IXamlLineInfoConsumer xamlLineInfoConsumer, MS.Internal.Xaml.Context.XamlContextStack<System.Windows.Markup.WpfXamlFrame> stack, System.Windows.Markup.IStyleConnector styleConnector)  Unknown
    PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader xamlReader, System.Xaml.IXamlObjectWriterFactory writerFactory, bool skipJournaledProperties, object rootObject, System.Xaml.XamlObjectWriterSettings settings, System.Uri baseUri)   Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.CreateObject(System.Windows.Baml2006.KeyRecord key) Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.OnGettingValue(object key, ref object value, out bool canCache) Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.OnGettingValuePrivate(object key, ref object value, out bool canCache)  Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.GetValueWithoutLock(object key, out bool canCache)  Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.GetValue(object key, out bool canCache) Unknown
    PresentationFramework.dll!System.Windows.DeferredResourceReference.GetValue(System.Windows.BaseValueSourceInternal valueSource) Unknown
    PresentationFramework.dll!System.Windows.StaticResourceExtension.TryProvideValueImpl(System.IServiceProvider serviceProvider, bool allowDeferredReference, bool mustReturnDeferredResourceReference)    Unknown
    PresentationFramework.dll!System.Windows.StaticResourceExtension.ProvideValueInternal(System.IServiceProvider serviceProvider, bool allowDeferredReference) Unknown
    System.Xaml.dll!MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(System.Windows.Markup.MarkupExtension me, System.IServiceProvider serviceProvider)   Unknown
    System.Xaml.dll!System.Xaml.XamlObjectWriter.Logic_ProvideValue(MS.Internal.Xaml.Context.ObjectWriterContext ctx)   Unknown
    System.Xaml.dll!System.Xaml.XamlObjectWriter.Logic_AssignProvidedValue(MS.Internal.Xaml.Context.ObjectWriterContext ctx)    Unknown
    System.Xaml.dll!System.Xaml.XamlObjectWriter.WriteEndMember()   Unknown
    PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.TransformNodes(System.Xaml.XamlReader xamlReader, System.Xaml.XamlObjectWriter xamlWriter, bool onlyLoadOneNode, bool skipJournaledProperties, bool shouldPassLineNumberInfo, System.Xaml.IXamlLineInfo xamlLineInfo, System.Xaml.IXamlLineInfoConsumer xamlLineInfoConsumer, MS.Internal.Xaml.Context.XamlContextStack<System.Windows.Markup.WpfXamlFrame> stack, System.Windows.Markup.IStyleConnector styleConnector)  Unknown
    PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader xamlReader, System.Xaml.IXamlObjectWriterFactory writerFactory, bool skipJournaledProperties, object rootObject, System.Xaml.XamlObjectWriterSettings settings, System.Uri baseUri)   Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.CreateObject(System.Windows.Baml2006.KeyRecord key) Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.OnGettingValue(object key, ref object value, out bool canCache) Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.OnGettingValuePrivate(object key, ref object value, out bool canCache)  Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.GetValueWithoutLock(object key, out bool canCache)  Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.GetValue(object key, out bool canCache) Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.GetValueWithoutLock(object key, out bool canCache)  Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.GetValue(object key, out bool canCache) Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.GetValueWithoutLock(object key, out bool canCache)  Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.GetValue(object key, out bool canCache) Unknown
    PresentationFramework.dll!System.Windows.ResourceDictionary.Lookup(object key, bool allowDeferredResourceReference, bool mustReturnDeferredResourceReference, bool canCacheAsThemeResource) Unknown
    PresentationFramework.dll!System.Windows.StaticResourceExtension.FindResourceInEnviroment(System.IServiceProvider serviceProvider, bool allowDeferredReference, bool mustReturnDeferredResourceReference)   Unknown
    PresentationFramework.dll!System.Windows.StaticResourceExtension.TryProvideValueImpl(System.IServiceProvider serviceProvider, bool allowDeferredReference, bool mustReturnDeferredResourceReference)    Unknown
    PresentationFramework.dll!System.Windows.StaticResourceExtension.ProvideValueInternal(System.IServiceProvider serviceProvider, bool allowDeferredReference) Unknown
    System.Xaml.dll!MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(System.Windows.Markup.MarkupExtension me, System.IServiceProvider serviceProvider)   Unknown
    System.Xaml.dll!System.Xaml.XamlObjectWriter.Logic_ProvideValue(MS.Internal.Xaml.Context.ObjectWriterContext ctx)   Unknown
    System.Xaml.dll!System.Xaml.XamlObjectWriter.Logic_AssignProvidedValue(MS.Internal.Xaml.Context.ObjectWriterContext ctx)    Unknown
    System.Xaml.dll!System.Xaml.XamlObjectWriter.WriteEndMember()   Unknown
    PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.TransformNodes(System.Xaml.XamlReader xamlReader, System.Xaml.XamlObjectWriter xamlWriter, bool onlyLoadOneNode, bool skipJournaledProperties, bool shouldPassLineNumberInfo, System.Xaml.IXamlLineInfo xamlLineInfo, System.Xaml.IXamlLineInfoConsumer xamlLineInfoConsumer, MS.Internal.Xaml.Context.XamlContextStack<System.Windows.Markup.WpfXamlFrame> stack, System.Windows.Markup.IStyleConnector styleConnector)  Unknown
    PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader xamlReader, System.Xaml.IXamlObjectWriterFactory writerFactory, bool skipJournaledProperties, object rootObject, System.Xaml.XamlObjectWriterSettings settings, System.Uri baseUri)   Unknown
    PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader xamlReader, bool skipJournaledProperties, object rootObject, System.Xaml.Permissions.XamlAccessLevel accessLevel, System.Uri baseUri) Unknown
    PresentationFramework.dll!System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext, object parent, bool closeStream)    Unknown

补充信息

使用的DataTemplate

<DataTemplate DataType="{x:Type shared:PreviewPageViewModel}">
<Grid Background="White">
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>
  <Image Source="{Binding PreviewPicturePath, Converter={StaticResource StringToImageSourceConverter}}" 
                 Stretch="Uniform" 
                 StretchDirection="Both"
                 Grid.Row="0"
                 Visibility="{Binding PicturePathValid, Converter={StaticResource BooleanToVisibilityConverter}}" />
  <ContentControl Grid.Row="0"
                          BorderBrush="DarkGray"
                          BorderThickness="10"
                          HorizontalAlignment="Center"
                          VerticalAlignment="Center"
                          Content="{Binding Path=FunctionViewAdapter}"
                          ContentTemplateSelector="{StaticResource HintTemplateSelector}"
                          Visibility="{Binding ShowFallbackPreview, Converter={StaticResource BooleanToVisibilityConverter}}"
                          Opacity="0.85">
  </ContentControl>
</Grid>

绑定属性与转换器代码

string directory = Path.GetDirectoryName(panelPath);
string panelPicturePath = Path.Combine(directory, "PreviewPicture.png");

if (File.Exists(panelPicturePath))
{
  PreviewPicturePath = panelPicturePath;
}

public class StringToImageSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
  if (!(value is string valueString))
  {
    return null;
  }
  try
  {
    ImageSource image = BitmapFrame.Create(new Uri(valueString), BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.OnLoad);
    return image;
  }
  catch { return null; }
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
  throw new NotImplementedException();
}
分析与解决方案

问题根源

从调用栈可以看到,WPF在加载图片时,尝试访问系统默认的sRGB颜色配置文件file:///C:/Windows/system32/spool/drivers/color/sRGB%20Color%20Space%20Profile.icm,但因文件权限不足、文件损坏、系统服务异常等原因,导致请求超时100秒,进而阻塞UI线程。该请求是WPF的ColorContext初始化过程中自动触发的,用于处理图片颜色管理,并非业务代码主动发起。

排查方向

  • 检查客户系统中该颜色配置文件是否存在,路径是否正确:C:\Windows\system32\spool\drivers\color\sRGB Color Space Profile.icm
  • 验证文件权限:确保运行软件的用户对该文件有读取权限
  • 检查系统的Windows Color System服务是否正常运行(服务名:WcsPlugInService)
  • 确认系统是否有损坏的系统文件,可运行sfc /scannow命令修复

解决办法

方法1:修改图片加载逻辑,避免自动加载颜色配置文件

在转换器中用流加载图片,并禁用颜色管理,绕开ColorContext的初始化:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
  if (!(value is string valueString))
  {
    return null;
  }
  try
  {
    using (var stream = new FileStream(valueString, FileMode.Open, FileAccess.Read))
    {
      var image = BitmapFrame.Create(stream, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.OnLoad);
      image.ColorContexts.Clear();
      return image;
    }
  }
  catch { return null; }
}

方法2:预加载颜色配置文件或替换为本地资源

  • 将系统的sRGB颜色配置文件复制到应用程序目录,在启动时预加载,避免后续请求超时
  • 在应用中嵌入自定义的sRGB配置文件,指定图片使用该配置

方法3:全局禁用WPF颜色管理功能

在App.xaml中添加配置,全局禁用颜色管理(注意:可能影响部分图片颜色显示效果,需测试验证):

<Application.Resources>
    <ColorContextManager.ColorContext="Ignore" />
</Application.Resources>

内容的提问来源于stack exchange,提问作者user3292642

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 12:15:31