B
Brad Huff
I have included a snippet below which illustrates the
problem with adding and removing controls in a repeating
fashion. At least on my computer (Windows XP) the
program crashes after several thousand iterations. Is
there a way to correct this simple program so it doesn't
crash or is there a bug with .NET 1.1?
Thanks, Brad
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using CustomDialogs;
using CustomControls;
using System.Threading;
public class Test{
public class MyForm:Form{
XButton button = new XButton();
XButton test = new XButton();
int count;
public MyForm(): base() {
InitializeComponent();
}
private void InitializeComponent(){
this.Width = 1000;
this.Height = 900;
this.Controls.Add(button);
button.Click +=
new EventHandler(click);
test.Location = new Point(300,300);
}
void click (object sender, EventArgs e){
for (int i = 0;i<30000;i++){
Controls.Add(test);
Controls.Remove(test);
count++;
button.Text = count.ToString();
button.Refresh();
}
}
}
public static void Main(string[] args)
{
MyForm form = new MyForm();
Application.Run(form);
}
}
problem with adding and removing controls in a repeating
fashion. At least on my computer (Windows XP) the
program crashes after several thousand iterations. Is
there a way to correct this simple program so it doesn't
crash or is there a bug with .NET 1.1?
Thanks, Brad
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using CustomDialogs;
using CustomControls;
using System.Threading;
public class Test{
public class MyForm:Form{
XButton button = new XButton();
XButton test = new XButton();
int count;
public MyForm(): base() {
InitializeComponent();
}
private void InitializeComponent(){
this.Width = 1000;
this.Height = 900;
this.Controls.Add(button);
button.Click +=
new EventHandler(click);
test.Location = new Point(300,300);
}
void click (object sender, EventArgs e){
for (int i = 0;i<30000;i++){
Controls.Add(test);
Controls.Remove(test);
count++;
button.Text = count.ToString();
button.Refresh();
}
}
}
public static void Main(string[] args)
{
MyForm form = new MyForm();
Application.Run(form);
}
}