Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Business forms registered after exception
Message
From
26/08/2005 10:37:50
 
 
To
All
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Business forms registered after exception
Environment versions
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01044309
Message ID:
01044309
Views:
52
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
Map
View

Click here to load this message in the networking platform