473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Events are running twice

I have been designing an application in Visual Studio 2005, and just about
everything is working, except all of my events run twice. They run through
correctly, but then they randomly run through a second time. For example, if
I click cancel on the main form, it properly triggers the event, but it does
so twice. The main program is program.cs, and it calls the others. Here is
the source code, its too long to list here, so here are some links:

http://www.joshkelahan.com/slu/AutoL...Program.cs.pdf
http://www.joshkelahan.com/slu/AutoL...rm_main.cs.pdf
http://www.joshkelahan.com/slu/AutoL...rm_cncl.cs.pdf
http://www.joshkelahan.com/slu/AutoL...t_about.cs.pdf

And here are the Designer files created by Visual Studio
http://www.joshkelahan.com/slu/AutoL...esigner.cs.pdf
http://www.joshkelahan.com/slu/AutoL...esigner.cs.pdf
http://www.joshkelahan.com/slu/AutoL...esigner.cs.pdf

Any help you can provide on how I can get these events to trigger only once
would be greatly appreciated.

Thanks!

Oct 4 '07 #1
3 1615
You're hooking the events up twice. :)

Do a quick search for "+=" on the event, put a breakpoint there, on see how
many times it gets called. I would be willing to bet, it's exactly two
times.

If you add an event handler, you need to remembe to remove it. Otherwise,
you can add it multiple times, and then it's called multiple times.

--
Chris Mullins

"jdkc4d" <jd****@discussions.microsoft.comwrote in message
news:F0**********************************@microsof t.com...
>I have been designing an application in Visual Studio 2005, and just about
everything is working, except all of my events run twice. They run
through
correctly, but then they randomly run through a second time. For example,
if
I click cancel on the main form, it properly triggers the event, but it
does
so twice. The main program is program.cs, and it calls the others. Here
is
the source code, its too long to list here, so here are some links:

http://www.joshkelahan.com/slu/AutoL...Program.cs.pdf
http://www.joshkelahan.com/slu/AutoL...rm_main.cs.pdf
http://www.joshkelahan.com/slu/AutoL...rm_cncl.cs.pdf
http://www.joshkelahan.com/slu/AutoL...t_about.cs.pdf

And here are the Designer files created by Visual Studio
http://www.joshkelahan.com/slu/AutoL...esigner.cs.pdf
http://www.joshkelahan.com/slu/AutoL...esigner.cs.pdf
http://www.joshkelahan.com/slu/AutoL...esigner.cs.pdf

Any help you can provide on how I can get these events to trigger only
once
would be greatly appreciated.

Thanks!

Oct 4 '07 #2
"Miro" <mi******@beero.netwrote:
Would you mind posting an example of code that was causing this... i
wouldn't mind just seeing what the cause was.

Was it something like "handles += onclick or something ?
If your code looked like:
Button1.OnClick += MyButtonHandler(...);
Button1.OnClick += MyButtonHandler(...);

When the user clicks button1 a single time, your method ("MyButtonHandler")
will actually be called twice.

If you're adding event handlers based on state, then you need to remember to
remove them as well:
Button1.Onclick -= MyButtonHandler(...);

--
Chris Mullins
Oct 5 '07 #3
Chris Mullins [MVP - C#] wrote:
"Miro" <mi******@beero.netwrote:
>Would you mind posting an example of code that was causing this... i
wouldn't mind just seeing what the cause was.

Was it something like "handles += onclick or something ?

If your code looked like:
Button1.OnClick += MyButtonHandler(...);
Button1.OnClick += MyButtonHandler(...);

When the user clicks button1 a single time, your method ("MyButtonHandler")
will actually be called twice.

If you're adding event handlers based on state, then you need to remember to
remove them as well:
Button1.Onclick -= MyButtonHandler(...);

--
Chris Mullins

Thank you

Miro
Oct 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kory Pukash | last post by:
I have an asp.net(2003) form that uses web server controls event architecture. The form has edit, cancel, save, delete buttons on it. When the delete button is clicked the following events fire. ...
4
by: Gaz | last post by:
This is impossible right?? This is a very simplified description of my form so don't worry if it sounds like I could do it a different way, it's just because I have simplified it. I have two...
10
by: Drakier Dominaeus | last post by:
This is my first time posting here, so please forgive me if I do anything incorrectly. I've been learning C# and working with different things and decided I wanted to get into Multi-Threading....
4
by: Sean Connery | last post by:
I have a Microsoft UI Process Application Block that is controlling child forms in an MDI parent container. The views node in the app.config file has been set to stayOpen=false. Because there...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
4
by: =?Utf-8?B?SmFtZXMgR2V1cnRz?= | last post by:
On my page, I have one repeater that contains a literal control and a nested repeater. The nested repeater contains a literal control. Both repeaters are databound with only one object (string). ...
2
by: glenn.nicol | last post by:
I have extensive experience in ASP.NET Visual Studio world. I am working on the Visual Web Developer 2005 Express Edition for a personal project and have found that controls are being called twice...
3
by: alma27 | last post by:
I discovered that when a Forn Keydown Event Or Form KeyPress event happens Each character is trapped twice on the same Event routine. I use VB6, and my form has KeyPreview property = TRUE. I was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.