Windows 10 Creators更新打破了WinForms应用程序/ BSOD

时间:2017-04-24 08:52:01

标签: windows winforms

在复杂的WinForms应用程序中有多个图层时,Windows 10 Creators崩溃。可以使用下面的代码轻松复制。当悬停或点击> = 40层之上的UI时,系统会因BSOD而崩溃。它应该成为一个例外。

有没有人知道调整以避免完全崩溃?

代码:

    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PanelLayers
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            int maxCount = 45;
            int count = 0;
            this.CreateLayers(this, maxCount, ref count);
        }

        private void CreateLayers(Control BaseControl, int MaxCount, ref int Count)
        {
            if(Count == MaxCount)
            {
                Button btn = new Button();
                btn.Text = "Click me";
                btn.Location = new Point(8, 8);
                btn.Click += btn_Click;
                BaseControl.Controls.Add(btn);
            }
            else
            {
                Count++;
                Panel pnl = new Panel();
                pnl.Dock = DockStyle.Fill;
                try
                {
                    BaseControl.Controls.Add(pnl);
                    this.CreateLayers(pnl, MaxCount, ref Count);
                }
                catch(Exception ex)
                {
                    MessageBox.Show(String.Format("Exception hit at count {0}{1}{2}{1}{3}", Count, Environment.NewLine, ex.Message, ex.StackTrace));
                }
            }
        }

        void btn_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello Creators Update!");
            this.Close();
        }
    }
}

2 个答案:

答案 0 :(得分:1)

它看起来可能与Windows 8 / Windows Server 2012上的其他问题(相同?)有关。请参阅here

<强>更新

Microsoft提供了一个修复程序:https://support.microsoft.com/en-us/help/4022716/windows-10-update-kb4022716

以下是其描述:

  

“Windows Forms(WinForms)的解决问题(错误0x7F)导致系统在升级到Creators Update后崩溃。”

答案 1 :(得分:0)

似乎相同,或者类似的问题在Win10 build 1803中再次出现。当在标签/窗口上移动鼠标进行播放时,以下代码迅速触发BSOD。

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace FormWithButton
{
    public class Form1 : Form
    {
        public Form1()
        {
            Control p = this;

            for (int i = 1; i < 48; i++) {
                var p2 = new Panel();
                p.Controls.Add(p2);
                p = p2;
            }

            var b = new Label();
            b.Text = "Hello";
            p.Controls.Add(b);
        }
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }
    }
}