Click here to Skip to main content
15,886,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,
In my application, I call form A, form A call form B (A and B in the dll). I want to close all form called in reference dll when application raise error. How can?
In Application, .NET have method End or Application.Exit(), but I don't know in dll, how to close all reference in dll but don't close my application. Please help me.
Thanks all.
Posted

1 solution

There is no direct way to do that.
However, you could add it yourself - it's not that difficult.
Create a static list within the DLL (it's probably worth adding a static class "DLLControl" or similar for this) of Form objects.
Each time one of the forms gets a Load event, add it to the static list, and add a handler to the FormClosing event.
In the FormClosing handler, check if the form is in the static list, and if so remove it.

Now, add a static method to the DLL:
C#
public static CloseAllForms()
   {
   List<Form> openForms = staticListOfForms;
   staticListOfForms = new List<Form>();
   foreach (form f in openForms)
      f.Close();
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900