Hello there fellow members.
I have two windows forms, and they call each other.
- Form 1 has a button that calls Form 2.
- Form 2 does not have an exit button, but rather a button that goes back to Form 1.
- Form 1 is the main form and the program is terminated from it.
Now, I have a background algorithm in Form 1 which must not work when going to Form 2, but when I go back from 2 to 1, that algorithm should work again.
So, I did the following:
- Code of the button that takes me from Form 1 to 2:
Form2 frm2 = new Form2();
frm2.Show();
this.Hide();
- Code of the button that takes me back from 2 to 1:
Form1 frm1 = new Form1();
this.Close();
frm1.Show();
However, this leads to a problem of Form replication. If I go through the forms back and forth a little bit, then back to the main form and close the application; some artifacts remain in the background. Instances of the application itself remain working (can be shut off from the Task Manager), so how do I make sure that once Form 1 is closed, the application and all extra instances created during this Form traversal are terminated?
Thanks in advance!