Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Business forms registered after exception
Message
De
26/08/2005 10:37:50
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Business forms registered after exception
Versions des environnements
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01044309
Message ID:
01044309
Vues:
51
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
Fil
Voir

Click here to load this message in the networking platform