G
Guest
Hi,
To properly clean up native resources, one should always use "using (Blah
blah = new Blah())" for types "Blah" that implement IDisposable. It seems to
me that the code generated by Visual Studio in Program.cs doesn't live by
this rule? A form is always IDisposable, so who calls the .Dispose() method
on the form?
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyForm());
}
And what about, if I change the code into this (below):
[STAThread]
static void Main()
{
MyForm myForm = new MyForm();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(myForm);
myForm.DoSomethingThatUsesTheFormObjectExtensivly();
}
The reason why I'm asking about this is because I'm having trouble with
system tray icons that are left after my application exits. Normally this
works fine, but when I stopped using Application.Run() things got hairy. I'm
not sure the normal Application.Run() because I'm trying to use
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run()
instead, in order to get a clean implementation of "single instance
application".
My question is, why isn't the Form1() instance in the generated code wrapped
into some kind of "using" statement? Is there some kind of special case going
on here?
Regards,
Martin
To properly clean up native resources, one should always use "using (Blah
blah = new Blah())" for types "Blah" that implement IDisposable. It seems to
me that the code generated by Visual Studio in Program.cs doesn't live by
this rule? A form is always IDisposable, so who calls the .Dispose() method
on the form?
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyForm());
}
And what about, if I change the code into this (below):
[STAThread]
static void Main()
{
MyForm myForm = new MyForm();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(myForm);
myForm.DoSomethingThatUsesTheFormObjectExtensivly();
}
The reason why I'm asking about this is because I'm having trouble with
system tray icons that are left after my application exits. Normally this
works fine, but when I stopped using Application.Run() things got hairy. I'm
not sure the normal Application.Run() because I'm trying to use
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run()
instead, in order to get a clean implementation of "single instance
application".
My question is, why isn't the Form1() instance in the generated code wrapped
into some kind of "using" statement? Is there some kind of special case going
on here?
Regards,
Martin