Skip to content

(Solved)C# problem, running methods multiple times for no reason

Mykel Stone

Asked Mar 5, 2008, 7:38 AM EST1 answer
Share
LinkedInX
I'm having a very freaking weird issue with C#, that doesn't seem to be making sense to me, sorry for the length of this, but I feel I have to be detailed. I have a class called Core, in this class, I create instances of all the forms that my program uses. Theres a welcome form, a next button is clicked, which brings up another form that checks asks if the user is a child, sending them to a form for either adults or children, this form checks the fields, and if the required information is entered, consolidates that information and creates 3 pages, presents a preview of each page on the last form, and the user clicks print to prints it if it looks alright, otherwise he can go back and edit.

What is happening is, things like the checking of the forms, button clicks, and the printing, it will begin to repeat these actions more than once. Every time the form is brought up, this behavior will increment, so if I start on the adult form, enter the information a click next, it'll go to the print form, it'll print once, but if i go to edit, the adult form will do everything twice, after i go back to the print form, the same behavior will occur on that one as well.

All controls are created at run time, and each form is hidden, its never destroyed, when I switch between forms, all I do is show the next form, and hide the previous one. And its happening with every method in each form. I've never had this happen before, what could be causing it??

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    I actually solved this myself, i have a method to bring the form into view, and setup all the controls, what was happening was, some how the controls seemed to be getting multiple handles, I think this was due to the Controls.Add() method, but when I'd click the button, or print or whatever, it would call multiple handles, thus it would happen multiple times.
    0