When you have many layers in a complex WinForms application, Windows 10 Creators crashes. This can be easily reproduced using the code below. When you hover or click on the user interface over> 40 layers, the system crashes using the BSOD. This should be an exception.
Does anyone know the settings to avoid a complete failure?
the code:
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();
}
}
}
source
share