好的。这个有点笨拙。
我正在为 Access 数据库编写前端(我知道,重新发明轮子)。这个前端很简单。个人可以添加新条目或搜索现有条目。两者都工作正常。该程序是自我更新的,虽然非常简单。它比较已执行程序的当前文件版本(不是程序集),并用远程驱动器版本引用自身以查看哪个更新。如果远程驱动器的可执行文件较新,我会生成一个批处理文件来更新脚本,方法是杀死当前程序,将较新的程序复制到与旧程序相同的目录,然后自动打开新程序。每次用户打开程序时都会进行此更新检查。
我不确定这是否相关,但我最近一直在编辑该过程以在 XP 和 7 上工作。因此,我需要对其进行修改以适应文件路径中的空格(文档和设置 - XP)。这一切都很好,花花公子。
不知从何而来(似乎),该程序开始在我的测试 XP 机器上持续崩溃(在 2 台不同的 XP 机器上验证)。我的个人机器正在运行 7,并且完全按预期运行,包括更新,一切正常。
XP 上的崩溃是我 Home 表单的 InitializeComponent() 中未处理的异常。我的表单的快速布局如下:
- BaseForm.cs - 主窗体/父窗体。.exe 打开时启动的第一个表单。没有GUI,只存在调用其他孩子。
- Home.cs - BaseForm 的子级。包含主页 GUI 和按钮以调用其他表单,如添加/搜索条目。
我们不会进入其他表单,因为它在加载 Home.cs 表单之前崩溃。
我已将其范围缩小到在 Home 的 InitializeComponent() 中崩溃,在以下构造函数中:
public Home(string DB)
{
InitializeComponent();
database = DB;
lblVersion.Text = "Version: " + FileVersionInfo.GetVersionInfo(Directory.GetCurrentDirectory() + "\\KnowledgeBase.exe").ProductVersion;
}
并带有以下消息。抱歉颗粒状...屏幕截图的屏幕截图:我的代表少于 10 个,并且不会输入错误:
这是我的 InitializeComponent()
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Home));
this.btnNewEntry = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.btnSearch = new System.Windows.Forms.Button();
this.lblVersion = new System.Windows.Forms.Label();
this.linklblChangelog = new System.Windows.Forms.LinkLabel();
this.button1 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// btnNewEntry
//
this.btnNewEntry.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnNewEntry.Location = new System.Drawing.Point(391, 407);
this.btnNewEntry.Name = "btnNewEntry";
this.btnNewEntry.Size = new System.Drawing.Size(142, 43);
this.btnNewEntry.TabIndex = 0;
this.btnNewEntry.Text = "Add new entry";
this.btnNewEntry.UseVisualStyleBackColor = true;
this.btnNewEntry.Click += new System.EventHandler(this.btnNewEntry_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(184, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(349, 31);
this.label1.TabIndex = 1;
this.label1.Text = "Nationwide Knowledgebase";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label2.Location = new System.Drawing.Point(280, 41);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(147, 26);
this.label2.TabIndex = 2;
this.label2.Text = "RADS Edition";
//
// btnSearch
//
this.btnSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnSearch.Location = new System.Drawing.Point(190, 407);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(142, 43);
this.btnSearch.TabIndex = 3;
this.btnSearch.Text = "Search database";
this.btnSearch.UseVisualStyleBackColor = true;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// lblVersion
//
this.lblVersion.AutoSize = true;
this.lblVersion.Location = new System.Drawing.Point(3, 485);
this.lblVersion.Name = "lblVersion";
this.lblVersion.Size = new System.Drawing.Size(64, 13);
this.lblVersion.TabIndex = 4;
this.lblVersion.Text = "Version: null";
//
// linklblChangelog
//
this.linklblChangelog.AutoSize = true;
this.linklblChangelog.Location = new System.Drawing.Point(96, 485);
this.linklblChangelog.Name = "linklblChangelog";
this.linklblChangelog.Size = new System.Drawing.Size(58, 13);
this.linklblChangelog.TabIndex = 5;
this.linklblChangelog.TabStop = true;
this.linklblChangelog.Text = "Changelog";
//
// button1
//
this.button1.Location = new System.Drawing.Point(640, 480);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 7;
this.button1.Text = "test";
this.button1.UseVisualStyleBackColor = true;
this.button1.Visible = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(232, 85);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(247, 256);
this.pictureBox1.TabIndex = 8;
this.pictureBox1.TabStop = false;
//
// Home
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.GradientInactiveCaption;
this.ClientSize = new System.Drawing.Size(727, 512);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.linklblChangelog);
this.Controls.Add(this.lblVersion);
this.Controls.Add(this.btnSearch);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnNewEntry);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Home";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Home";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Home_FormClosed);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
为什么它只在 XP 上在 InitializeComponent() 上崩溃?为什么它刚刚开始这样做?该领域的前几周开发进展顺利。
我试过取出整个 Update() 过程,但这并没有改变任何东西。
谢谢阅读。
更新: Jon Skeet 建议我使用的图标使程序崩溃。事实证明确实如此。删除图标可以让表单在 XP 上正常工作(同样,在 7 上从来不是问题)。更有趣的是,这个问题等了 2 周后才显现出来,因为我在开发中使用这个图标已经很长时间了。我将在稍后讨论它发生的原因,但与此同时我还有更多代码要编写。
感谢大家。