Information générale
Catégorie:
The Mere Mortals .NET Framework
Titre:
Business forms registered after exception
Versions des environnements
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
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement