3

ユーザーがマシンをロック/ロック解除したとき、またはユーザーが ctrl-alt-delete を押してから Esc キーを押したときに (必ずしもロックインするとは限りません)、Windows XP で .NET 4.0 (WPF ではなく WinForm) アプリケーションがクラッシュする問題をデバッグしています。このシナリオ -- ただし、ロック、タスク マネージャーの起動などのオプションがあります)。これは非常に再現性があります。

それは絵を描くことに関連していToolStripComboBoxます。これは、フードの下にAccessViolationExceptionあるいくつかのルーチンで を生成しています。gdiplus

いくつかの異なる方法でクラッシュするのを見てきましたが、すべてこのコントロールを描画する同じ領域にあります。1 つのスタック トレースを次に示します。

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画面の重要性について誰か提案がありますか?

編集:

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;
    }
}

編集2:

Windows XP Media Center エディションではこれを再現できませんでした。今のところ XP Pro だけです。

4

1 に答える 1

1

この問題はしばらく前からありました。同じコール スタックで、ユーザーが ctrl-alt-del を実行してエスケープしたときに発生します。シナリオは、WinForm コントロールと WPF コントロールが混在する WinForm アプリで発生するという点で少し異なります。アプリでは、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 を抑制する必要がありますが、特定のシナリオでは、この例外が伝播されています。

解決策を提供できず申し訳ありませんが、この情報が役立つことを願っています。

于 2012-09-04T09:20:03.857 に答える