Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event Called more than once in vb.net

Status
Not open for further replies.

spidydotnet

IS-IT--Management
Jun 7, 2003
18
0
0
GB
Hi guys.
I've got a strange problem. Here are the steps which explains it quite clearly.

This is an inherited form and has a list box in it.

1) I open a form (which has got data connectivity and bindings) it is working fine. And I close it.
2) I open the same form again, It takes couple of seconds more to open and all the events in it looks fine. But when I starting working with data I observed each SelectedIndexChanged event is being called twice.

3) I closed the previous form and opened it again. Now, the event is being called 4 times.

4) Close it and open again, 8 times.

I can't really understand what I am doing wrong. I can't really paste the code here as it is a very big one. I can do that if asked.

thanks for any help

Spidy.NET
'Discussion is Knowledge'
 
Find where you hook up to your event handlers and insert a break point. Make certain that these event handlers only hooked up once in the life time of your form.

It sounds like when you close your form, the instance is not being disposed of. Then when you open it a second time, you are doubling the number of event handlers by hooking them up a second time.

This could happen if you have coded the event handlers yourself in the code that displays the Form rather than in the constructor or by using the IDE (which puts this code in the constructor for you).
 
I found the solution.. It is basically not clearing up the memory after the form is closed. So, when the form is opened again..It is firing the events twice and causing.

Now, before closing the form I am clearing all the objects in that form and then closing the form. After doing that the performance of the form is increased.

Spidy.NET
'Discussion is Knowledge'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top