XP Pro 上使用 WebBrowser 控件绘制 ToolStripComboBox 时出现访问冲突

2024-01-28

我正在调试一个问题,即当用户锁定/解锁计算机或用户按 ctrl-alt-delete 然后按 escape(不一定锁定)时,.NET 4.0(WinForm,而不是 WPF)应用程序在 Windows XP 上崩溃这种情况——但他们可以选择锁定、启动任务管理器等)。这是非常可重复的。

与画画有关ToolStripComboBox。这正在生成一个AccessViolationException在一些gdiplus引擎盖下的例程。

我见过它崩溃的几种不同方式,但都在绘制此控件的同一区域中。这是一个堆栈跟踪:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Drawing.SafeNativeMethods.Gdip.GdipFillRectangleI(HandleRef graphics, HandleRef brush, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Drawing.Graphics.FillRectangle(Brush brush, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Drawing.Graphics.FillRectangle(Brush brush, Rectangle rect)
at System.Windows.Forms.ToolStripComboBox.ToolStripComboBoxControl.ToolStripComboBoxFlatComboAdapter.DrawFlatComboDropDown(ComboBox comboBox, Graphics g, Rectangle dropDownRect)
at System.Windows.Forms.ComboBox.FlatComboAdapter.DrawFlatCombo(ComboBox comboBox, Graphics g)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
...

有谁对如何解决这个问题有建议,或者机器锁定/解锁或 ctrl-alt-delete 屏幕的重要性是什么?

EDIT:

我将其归结为粘贴在下面的一个简单应用程序,它在 XP Pro 上可以很好地重现。这是非常普通的——大约是我们能得到的最简单的。一切都是在 UI 线程上创建/操作的。

namespace Test
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }

    public class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            webBrowser2.Navigate("http://www.cnn.com");
        }

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer();
            this.webBrowser2 = new System.Windows.Forms.WebBrowser();
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel();
            this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox();
            this.toolStripContainer1.ContentPanel.SuspendLayout();
            this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
            this.toolStripContainer1.SuspendLayout();
            this.toolStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // toolStripContainer1
            // 
            this.toolStripContainer1.BottomToolStripPanelVisible = false;
            // 
            // toolStripContainer1.ContentPanel
            // 
            this.toolStripContainer1.ContentPanel.Controls.Add(this.webBrowser2);
            this.toolStripContainer1.ContentPanel.Size = new System.Drawing.Size(555, 268);
            this.toolStripContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.toolStripContainer1.LeftToolStripPanelVisible = false;
            this.toolStripContainer1.Location = new System.Drawing.Point(0, 0);
            this.toolStripContainer1.Name = "toolStripContainer1";
            this.toolStripContainer1.RightToolStripPanelVisible = false;
            this.toolStripContainer1.Size = new System.Drawing.Size(555, 296);
            this.toolStripContainer1.TabIndex = 1;
            this.toolStripContainer1.Text = "toolStripContainer1";
            // 
            // toolStripContainer1.TopToolStripPanel
            // 
            this.toolStripContainer1.TopToolStripPanel.Controls.Add(this.toolStrip1);
            // 
            // webBrowser2
            // 
            this.webBrowser2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.webBrowser2.Location = new System.Drawing.Point(0, 0);
            this.webBrowser2.MinimumSize = new System.Drawing.Size(20, 20);
            this.webBrowser2.Name = "webBrowser2";
            this.webBrowser2.Size = new System.Drawing.Size(555, 268);
            this.webBrowser2.TabIndex = 0;
            // 
            // toolStrip1
            // 
            this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None;
            this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripLabel1,
            this.toolStripComboBox1});
            this.toolStrip1.Location = new System.Drawing.Point(3, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(173, 28);
            this.toolStrip1.TabIndex = 0;
            // 
            // toolStripLabel1
            // 
            this.toolStripLabel1.Name = "toolStripLabel1";
            this.toolStripLabel1.Size = new System.Drawing.Size(38, 25);
            this.toolStripLabel1.Text = "blah";
            // 
            // toolStripComboBox1
            // 
            this.toolStripComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.toolStripComboBox1.Items.AddRange(new object[] {
            "a b",
            "c",
            "d",
            "e",
            "f"});
            this.toolStripComboBox1.Name = "toolStripComboBox1";
            this.toolStripComboBox1.Size = new System.Drawing.Size(121, 28);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(555, 296);
            this.Controls.Add(this.toolStripContainer1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.toolStripContainer1.ContentPanel.ResumeLayout(false);
            this.toolStripContainer1.TopToolStripPanel.ResumeLayout(false);
            this.toolStripContainer1.TopToolStripPanel.PerformLayout();
            this.toolStripContainer1.ResumeLayout(false);
            this.toolStripContainer1.PerformLayout();
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.ResumeLayout(false);
        }
        #endregion

        private ToolStripContainer toolStripContainer1;
        private ToolStrip toolStrip1;
        private ToolStripLabel toolStripLabel1;
        private ToolStripComboBox toolStripComboBox1;
        private WebBrowser webBrowser2;
    }
}

EDIT 2:

我无法在 Windows XP Media Center 版本上重现这一点,到目前为止只能在 XP Pro 上重现。


我们遇到这个问题已经有一段时间了。相同的调用堆栈,当用户执行 ctrl-alt-del 和 escape 时会发生。 场景有点不同,因为它发生在我们的 WinForm 应用程序中,该应用程序是 WinForm 和 WPF 控件的混合体。在应用程序中,我们有一个托管在 ElementHost 中的 WPF UserControl,当该组件位于浮动窗口中、悬停在正在重新绘制的 WinForm 控件上并且屏幕被锁定和解锁时,会引发 AccessViolationException 并且应用程序崩溃。我应该提到的是,我们也在使用 Infragistics UltraDockWorkspace。

我们还没有找到解决方案,但是最近使用 MS 源进行调试时,我注意到抛出异常的方法处有这样的注释(在 System.Drawing 中的 Graphics.cs 中):

         /// <devdoc>
    ///     GDI+ will return a 'generic error' with specific win32 last error codes when
    ///     a terminal server session has been closed, minimized, etc...  We don't want 
    ///     to throw when this happens, so we'll guard against this by looking at the
    ///     'last win32 error code' and checking to see if it is either 1) access denied 
    ///     or 2) proc not found and then ignore it. 
    ///
    ///     The problem is that when you lock the machine, the secure desktop is enabled and 
    ///     rendering fails which is expected (since the app doesn't have permission to draw
    ///     on the secure desktop). Not sure if there's anything you can do, short of catching
    ///     the desktop switch message and absorbing all the exceptions that get thrown while
    ///     it's the secure desktop. 
    /// </devdoc>
    private void CheckErrorStatus(int status) { 
        if (status != SafeNativeMethods.Gdip.Ok) { 
            // Generic error from GDI+ can be GenericError or Win32Error.
            if (status == SafeNativeMethods.Gdip.GenericError || status == SafeNativeMethods.Gdip.Win32Error) { 
                int error = Marshal.GetLastWin32Error();
                if (error == SafeNativeMethods.ERROR_ACCESS_DENIED || error == SafeNativeMethods.ERROR_PROC_NOT_FOUND ||
                        //here, we'll check to see if we are in a term. session...
                        (((UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_REMOTESESSION) & 0x00000001) != 0) && (error == 0))) { 
                        return;
                    } 
                } 

            //legitimate error, throw our status exception 
            throw SafeNativeMethods.Gdip.StatusException(status);
        }
    }

根据我的理解,由于安全桌面模式下的渲染,AccessViolationException 应在此处被抑制,但在某些情况下,此异常正在传播。

抱歉,我无法提供解决方案,但希望这些信息有用。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

XP Pro 上使用 WebBrowser 控件绘制 ToolStripComboBox 时出现访问冲突 的相关文章

  • “你好世界!!”在 .NET 4 中生成 3500 个页面错误

    我正在运行 Windows Vista 和 Visual Studio 2010 使用 NET 4 2 GB RAM 和大约 800 MB 可用空间 我创建了一个 Windows 窗体应用程序 但没有向其中添加任何代码 只需在发布模式下编译
  • 需要 TensorFlow 依赖项。如何在 Windows 上运行 TensorFlow

    我有兴趣让 TensorFlow 在 Windows 上运行 但目前我意识到这是不可能的 因为某些依赖项无法在 Windows 上使用 例如巴泽尔 之所以出现这种需求 是因为据我目前了解 从 TensorFlow 访问 GPU 的唯一方法是
  • 从经典 ASP 调用 .Net C# DLL 方法

    我正在开发一个经典的 asp 项目 该项目需要将字符串发送到 DLL DLL 会将其序列化并发送到 Zebra 热敏打印机 我已经构建了我的 DLL 并使用它注册了regasm其次是 代码库这使得 IIS 能够识别它 虽然我可以设置我的对象
  • 枚举扩展方法

    在vs2008中 是否可以编写适用于任何枚举的扩展方法 我知道您可以针对特定枚举编写扩展方法 但我希望能够使用单个扩展方法对每个枚举进行处理 这可能吗 是的 只需针对基础进行编码Enum类型 例如 public static void So
  • 使用.Net/C# 计算集合的频率分布

    是否有一种快速 简单的方法来使用 Linq 或其他方式计算 Net 集合的频率分布 例如 任意长的 List 包含许多重复项 遍历列表并计算 跟踪重复次数的巧妙方法是什么 查找列表中重复项的最简单方法是将其分组 如下所示 var dups
  • 游戏内的java.awt.Robot?

    我正在尝试使用下面的代码来模拟击键 当我打开记事本时 它工作正常 但当我打开我想使用它的游戏时 它没有执行任何操作 所以按键似乎不起作用 我尝试模拟鼠标移动和点击 这些动作确实有效 有谁知道如何解决这个问题 我发现这个问题 如何在游戏中使用
  • 如何实例化 ODataQueryOptions

    我有一个工作 简化 ODataController用下面的方法 public class MyTypeController ODataController HttpGet EnableQuery ODataRoute myTypes pub
  • 如何在 Android 中使用 C# 生成的 RSA 公钥?

    我想在无法假定 HTTPS 可用的情况下确保 Android 应用程序和 C ASP NET 服务器之间的消息隐私 我想使用 RSA 来加密 Android 设备首次联系服务器时传输的对称密钥 RSA密钥对已在服务器上生成 私钥保存在服务器
  • 在 WPF 中使用 ReactiveUI 提供长时间运行命令反馈的正确方法

    我有一个 C WPF NET 4 5 应用程序 用户将用它来打开某些文件 然后 应用程序将经历很多动作 读取文件 通过许多插件和解析器传递它 这些文件可能相当大 gt 100MB 因此这可能需要一段时间 我想让用户了解 UI 中发生的情况
  • 从 mvc 控制器使用 Web api 控制器操作

    我有两个控制器 一个mvc控制器和一个api控制器 它们都在同一个项目中 HomeController Controller DataController ApiController 如果我想从 HomeController 中使用 Dat
  • HttpWebRequest/HttpResponse:如何在响应中发送数据?

    我有一个客户端和一个服务器 在客户端我有 HttpWebRequest request HttpWebRequest WebRequest Create http localhost fa Default aspx request Meth
  • 对于多重继承,使用隐式转换而不是 QueryInterface() 是否合法?

    假设我有一个类实现两个或多个 COM 接口 正如here https stackoverflow com questions 1742848 why exactly do i need an explicit upcast when imp
  • Winforms 中的 WPF ElementHost 最大化时崩溃 (Windows)

    我正在尝试将新的 WPF 控件集成到现有的 WinForms 应用程序中 并使用 ElementHost Dock Fill 来托管以下 XAML UserControl NET 4 当我将 WinForm 设置为最大化时 我的整个操作系统
  • 如何有效确保小数值至少有 N 位小数

    我想在进行算术运算之前有效地确保十进制值至少有 N 个位置 在下面的示例中 3 显然我可以格式化 0 000 然后解析 但它的效率相对较低 我正在寻找一种避免与字符串转换的解决方案 我尝试过以下解决方案 decimal d 1 23M d
  • 不在焦点时响应键盘? (C#、Vista)

    我正在尝试编写一个应用程序 只要按下 Shift 键 无论当前哪个应用程序具有焦点 它都会做出响应 我尝试过这个SetWindowsHookEx 与GetKeyboardState 但这两种方法仅在应用程序窗口具有焦点时才有效 我需要它在全
  • NodeJS Express Windows 最大连接数设置

    在哪里设置nodejs的最大连接数 用于使用express get 在 Windows 10 中 与linux中的最大文件 描述符 设置有关吗 有该设置的 Windows 版本吗 最好是在nodejs中进行设置 以便在迁移到unix时兼容
  • Windows 7 任务栏:捕获缩略图

    是否可以从 Win7 任务栏捕获 实时 缩略图 我想在我的应用程序中显示 另一个窗口的 预览 但如何使用 NET 提取这些预览 Yes MSDN 杂志解释了如何 http msdn microsoft com en us magazine
  • 什么时候值得使用 BindingSource?

    我想我非常了解 BindingSource 类的作用 即在数据源和 UI 控件之间提供一个间接层 它实现了 IBindingList 接口 因此还提供了对排序的支持 而且我已经经常使用它 没有太多问题 但我想知道我使用它的频率是否超过了应有
  • .NET 中是否有内置函数可以对密码进行哈希处理?

    我看到这个问题加密 散列数据库中的纯文本密码 https stackoverflow com questions 287517 encrypting hashing plain text passwords in database 我知道我
  • teracopy 如何替换默认的 Windows 副本

    我问了这个问题Windows 文件复制内部结构 动态加密 https stackoverflow com questions 24220382 windows file copy internals on the fly encryptio

随机推荐