.net 在XP Pro上使用WebBrowser控件访问绘图ToolStripComboBox
我正在调试一个问题,当用户锁定/解锁计算机时,或者当用户点击ctrl-alt-delete然后点击escape时,.NET 4.0(WinForm,而不是WPF)应用程序在Windows XP上崩溃(在这种情况下不一定要锁定,但他们可以选择锁定、打开任务管理器等)。这是非常可复制的 它与绘制.net 在XP Pro上使用WebBrowser控件访问绘图ToolStripComboBox,.net,windows,.net,Windows,我正在调试一个问题,当用户锁定/解锁计算机时,或者当用户点击ctrl-alt-delete然后点击escape时,.NET 4.0(WinForm,而不是WPF)应用程序在Windows XP上崩溃(在这种情况下不一定要锁定,但他们可以选择锁定、打开任务管理器等)。这是非常可复制的 它与绘制ToolStripComboBox有关。这将在引擎盖下面的一些gdiplus例程中生成一个AccessViolationException 我看到它崩溃的方式有很多种,但都是在同一个区域绘制这个控件。这里有一
ToolStripComboBox
有关。这将在引擎盖下面的一些gdiplus
例程中生成一个AccessViolationException
我看到它崩溃的方式有很多种,但都是在同一个区域绘制这个控件。这里有一个堆栈跟踪:
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;
}
}
名称空间测试
{
静态类程序
{
///
///应用程序的主要入口点。
///
[状态线程]
静态void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(新Form1());
}
}
公开课表格1:表格
{
公共表格1()
{
初始化组件();
}
私有void Form1_加载(对象发送方,System.EventArgs e)
{
webBrowser2.导航(“http://www.cnn.com");
}
///
///必需的设计器变量。
///
private System.ComponentModel.IContainer components=null;
///
///清理所有正在使用的资源。
///
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
///
///设计器支持所需的方法-不修改
///使用代码编辑器显示此方法的内容。
///
私有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.toolstripcombox1=new System.Windows.Forms.toolstripcombox1();
this.toolStripContainer1.ContentPanel.SuspendLayout();
this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
this.toolStripContainer1.SuspendLayout();
this.toolStrip1.SuspendLayout();
这个.SuspendLayout();
//
//toolStripContainer1
//
this.toolStripContainer1.BottomToolStripPanelVisible=false;
//
//toolStripContainer1.ContentPanel
//
this.toolStripContainer1.ContentPanel.Controls.Add(this.webBrowser2);
this.toolStripContainer1.ContentPanel.Size=新系统.Drawing.Size(555268);
this.toolStripContainer1.Dock=System.Windows.Forms.DockStyle.Fill;
this.toolStripContainer1.LeftToolStripPanelVisible=false;
this.toolStripContainer1.Location=新系统.Drawing.Point(0,0);
this.toolStripContainer1.Name=“toolStripContainer1”;
this.toolStripContainer1.RightToolStripPanelVisible=false;
this.toolStripContainer1.Size=新系统图尺寸(555296);
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=新系统.Drawing.Point(0,0);
this.webBrowser2.MinimumSize=新系统图纸尺寸(20,20);
this.webBrowser2.Name=“webBrowser2”;
this.webBrowser2.Size=新系统图纸尺寸(555268);
this.webBrowser2.TabIndex=0;
//
//toolStrip1
//
this.toolStrip1.Dock=System.Windows.Forms.DockStyle.None;
this.toolStrip1.Items.AddRange(新的System.Windows.Forms.ToolStripItem[]{
这个.toolStripLabel1,
这个.toolstripCombox1});
this.toolStrip1.Location=新系统图点(3,0);
this.toolStrip1.Name=“toolStrip1”;
this.toolStrip1.Size=新系统图纸尺寸(173,28);
this.toolStrip1.TabIndex=0;
//
//toolStripLabel1
//
this.toolStripLabel1.Name=“toolStripLabel1”;
this.toolStripLabel1.Size=新系统图尺寸(38,25);
/// <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);
}
}