Hello everybody!
I wrote an project with one class (Class) and two forms (Form1, Form2):
-----------------------------------Form2AndClass1B egin----------------------
------------------
public class Class
{
public void Form2_Closed(ob ject sender, System.EventArg s e)
{
((Form2)sender) .Closed -= new System.EventHan dler(Form2_Clos ed);
}
~Class()
{
System.Windows. Forms.MessageBo x.Show("~Class destroyed");
}
}
public class Form2 : System.Windows. Forms.Form
{
.....
}
-----------------------------------Form2AndClass1E nd------------------------
----------------
and application form Form1:
-----------------------------------Form1Begin-------------------------------
---------
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Button button1;
....
private void button1_Click(o bject sender, System.EventArg s e)
{
Form2 frm = new Form2();
Class cls = new Class();
frm.Closed += new System.EventHan dler(cls.Form2_ Closed);
frm.Show();
frm = null;
cls = null;
}
[STAThread]
static void Main()
{
System.Windows. Forms.Applicati on.Run(new Form1());
}
}
}
-----------------------------------Form1End---------------------------------
-------
After Application starts and I Click on button1, then close Form2, then
objects Form2 and Class1 must be disposed and destroyed automatically
(project don't have any reference on its at this time!!!)??!!
Say me, please, why objects Form2 and Class1 destroyed periodically - from
time to time??
--
thank in avanced,
WBR, Roman S. Golubin
PS: I sorry for my bad english. Really sorry ;-(
I wrote an project with one class (Class) and two forms (Form1, Form2):
-----------------------------------Form2AndClass1B egin----------------------
------------------
public class Class
{
public void Form2_Closed(ob ject sender, System.EventArg s e)
{
((Form2)sender) .Closed -= new System.EventHan dler(Form2_Clos ed);
}
~Class()
{
System.Windows. Forms.MessageBo x.Show("~Class destroyed");
}
}
public class Form2 : System.Windows. Forms.Form
{
.....
}
-----------------------------------Form2AndClass1E nd------------------------
----------------
and application form Form1:
-----------------------------------Form1Begin-------------------------------
---------
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Button button1;
....
private void button1_Click(o bject sender, System.EventArg s e)
{
Form2 frm = new Form2();
Class cls = new Class();
frm.Closed += new System.EventHan dler(cls.Form2_ Closed);
frm.Show();
frm = null;
cls = null;
}
[STAThread]
static void Main()
{
System.Windows. Forms.Applicati on.Run(new Form1());
}
}
}
-----------------------------------Form1End---------------------------------
-------
After Application starts and I Click on button1, then close Form2, then
objects Form2 and Class1 must be disposed and destroyed automatically
(project don't have any reference on its at this time!!!)??!!
Say me, please, why objects Form2 and Class1 destroyed periodically - from
time to time??
--
thank in avanced,
WBR, Roman S. Golubin
PS: I sorry for my bad english. Really sorry ;-(
Comment