G
Guest
Hi
I'm trying to show a form as a dialog (using the .ShowDialog() method). After showing the dialog, I want to dispose of the form
I use this design (simplified to clarify the point)
MyDialog dlg
tr
dlg = new MyDialog()
dlg.ShowDialog(this)
if(dlg.DialogResult == DialogResult.Yes
// Process the selections in the dialog her
catch(Exception ex
// Handle the error her
finall
if(dlg!=null){dlg.Dispose();
The C# compiler refuses to compile this because of the uninitialized dlg variable in the finally block
Is there any other way to ensure that the dispsose method is called, regardless of any thrown errors
I come from VB .NET where the design above pose no problems, even with Option Strict turned on
Any help is appreciated
Regards
Jakob
I'm trying to show a form as a dialog (using the .ShowDialog() method). After showing the dialog, I want to dispose of the form
I use this design (simplified to clarify the point)
MyDialog dlg
tr
dlg = new MyDialog()
dlg.ShowDialog(this)
if(dlg.DialogResult == DialogResult.Yes
// Process the selections in the dialog her
catch(Exception ex
// Handle the error her
finall
if(dlg!=null){dlg.Dispose();
The C# compiler refuses to compile this because of the uninitialized dlg variable in the finally block
Is there any other way to ensure that the dispsose method is called, regardless of any thrown errors
I come from VB .NET where the design above pose no problems, even with Option Strict turned on
Any help is appreciated
Regards
Jakob