General information
Category:
The Mere Mortals .NET Framework
Title:
Business forms registered after exception
Environment versions
Network:
Windows 2003 Server
Hi,
I think this may be a bug in MM but I am not sure. I use System.Activator.CreateInstance(Type type) to instantiate business forms, the problem is that the form is still registered with the mmAppDesktop.FormMgr's form collection after an exception has been thrown from CreateInstance(Type type).
The following scenario and code may help explain :
I only want business forms to be instantiated once so I have a method that checks the form collection before using Activator.CreateInstance() to make a new form instance.
private void ShowChildForm(Type formType)
{
mmBusinessForm form = mmAppDesktop.FormMgr.Get(formType) as mmBusinessForm;
if (form == null)
{
try
{
form = (mmBusinessForm) Activator.CreateInstance(formType);
}
catch (Exception e)
{
mmAppDesktop.FormMgr.Remove(mmAppDesktop.FormMgr.Get(formType));
mmExceptionForm exceptForm = new mmExceptionForm(e.InnerException.Message,e.InnerException.StackTrace);
mmAppDesktop.Log.WriteException(e.InnerException);
exceptForm.Show();
return;
}
}
mmAppDesktop.FormMgr.Show(form, this);
form.Focus();
}
I had to add the line mmAppDesktop.FormMgr.Remove(mmAppDesktop.FormMgr.Get(formType)); to remove forms that had registered itself even after the default constructor failed. The problem with the form registering itself is that the next time the user tries to open the form (after an exception), the form will not be null and the entire application falls over in a smoldering heap showing the original error plus the last one.
If there is another way of not having to create a new business form instance each time the user choses the meny item for that form then that would be great.
With regards,
Andrew
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only